Files
javademos/jpms-basics/src/com.acme.mapper/com/acme/mapper/Mapper.java
T
asmhatreandClaude Sonnet 5.5 de2660e998 Add jpms-basics module: JPMS for working developers, exports vs opens, split packages, automatic modules, jdeps and jlink on JDK 25
Five modules built with plain javac/java/jdeps/jlink on Temurin 25.0.5.1. Sources, broken/ cases,
run.sh and captured transcripts in output/. README row added.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4XrpfdpsacrvqnrBM
2026-11-26 20:53:17 +05:30

24 lines
785 B
Java

package com.acme.mapper;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* A twenty-line stand-in for Jackson, Hibernate or Spring: it reads every declared field of
* any object it is given, private ones included. That is exactly the kind of code that
* needs `opens` from the module that owns the object.
*/
public final class Mapper {
private Mapper() { }
public static Map<String, Object> toMap(Object o) throws ReflectiveOperationException {
Map<String, Object> m = new LinkedHashMap<>();
for (Field f : o.getClass().getDeclaredFields()) {
f.setAccessible(true); // <- the call that the module system polices
m.put(f.getName(), f.get(o));
}
return m;
}
}