Class PojoMapper
- java.lang.Object
-
- org.actioncontroller.optional.json.PojoMapper
-
public class PojoMapper extends Object
Convert from JSON structures to regular Java objects. Supports primitive numbers (byte, short, int, long, float, double, BigDecimal, BigInteger), simple values (for String, character, Instant, LocalDate, ZonedDateTime, OffsetDateTime, UUID, URL, URI and InetAddress), Enums, Collections, Maps, Streams and Java beans. You can even add your own converters.Usage:
PojoMapper pojoMapper = new PojoMapper(); pojoMapper.addObjectMapper(MyClass.class, (json, mapper) -> new MyClass()); MyClass o = pojoMapper.map(json, MyClass.class);
-
-
Constructor Summary
Constructors Constructor Description PojoMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PojoMapperaddMapper(Type type, ObjectFromJsonMapper<?> mapper)<T> PojoMapperaddObjectFactoryMapper(Class<T> type, String discriminatorProperty, Function<String,? extends T> factory)protected StringfromUnderscoreToCamelCase(String key)protected Class<?>getClassType(Type type)protected StringgetterName(String fieldName)<T> Tmap(javax.json.JsonValue json, Class<T> targetType)Map from json to a object of the specified target class<T> Tmap(javax.json.JsonValue json, Type targetType)Map from json to a object of the specified target typeprotected ObjectnewInstance(Type targetType)Objectread(Reader reader, Type returnType)Read from json string to a object of the specified target typePojoMapperrejectUnknownFields()protected StringsetterName(String fieldName)protected StringsetterNameCamelCase(String fieldName)<T> TwriteFields(javax.json.JsonObject json, T o)
-
-
-
Method Detail
-
map
public <T> T map(javax.json.JsonValue json, Class<T> targetType)Map from json to a object of the specified target class
-
read
public Object read(Reader reader, Type returnType)
Read from json string to a object of the specified target type
-
map
public <T> T map(javax.json.JsonValue json, Type targetType)Map from json to a object of the specified target type
-
writeFields
public <T> T writeFields(javax.json.JsonObject json, T o)
-
addMapper
public PojoMapper addMapper(Type type, ObjectFromJsonMapper<?> mapper)
-
addObjectFactoryMapper
public <T> PojoMapper addObjectFactoryMapper(Class<T> type, String discriminatorProperty, Function<String,? extends T> factory)
-
rejectUnknownFields
public PojoMapper rejectUnknownFields()
-
-