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 toMap(Object o) throws ReflectiveOperationException { Map 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; } }