Package org.apache.johnzon.mapper
Class MappingGeneratorImpl
- java.lang.Object
-
- org.apache.johnzon.mapper.MappingGeneratorImpl
-
- All Implemented Interfaces:
MappingGenerator
public class MappingGeneratorImpl extends Object implements MappingGenerator
-
-
Field Summary
Fields Modifier and Type Field Description private MapperConfig
config
private jakarta.json.stream.JsonGenerator
generator
private Map<Object,String>
jsonPointers
private Mappings
mappings
-
Constructor Summary
Constructors Constructor Description MappingGeneratorImpl(MapperConfig config, jakarta.json.stream.JsonGenerator jsonGenerator, Mappings mappings)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private <T> Object
doConvertFrom(T value, Adapter<T,Object> converter)
private <T> void
doWriteIterable(Iterable<T> object, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
void
doWriteObject(Object object, jakarta.json.stream.JsonGenerator generator, boolean writeBody, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
private boolean
doWriteObjectBody(Object object, Collection<String> ignored, JsonPointerTracker jsonPointer, jakarta.json.stream.JsonGenerator generator)
jakarta.json.stream.JsonGenerator
getJsonGenerator()
private boolean
isDedup()
private static boolean
isFloat(Class<?> type)
private boolean
isInJsRange(Number longValue)
private static boolean
isInt(Class<?> type)
private void
writeArray(Class<?> type, Adapter itemConverter, String key, Object arrayValue, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
Write a JSON Array with a given Array Value, like byte[], int[], Person[] etc.private void
writeItem(Object o, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
private void
writeIterator(Adapter itemConverter, String key, ObjectConverter.Writer objectConverter, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer, jakarta.json.stream.JsonGenerator generator, Iterator<?> iterator, Object originalValue)
private jakarta.json.stream.JsonGenerator
writeMapBody(Map<?,?> object, Adapter itemConverter)
MappingGenerator
writeObject(Object object, jakarta.json.stream.JsonGenerator generator)
Write the given Object o into the current JSON layer.MappingGenerator
writeObject(String key, Object object, jakarta.json.stream.JsonGenerator generator)
private boolean
writePrimitives(Object value)
private boolean
writePrimitives(String key, Class<?> type, Object value, jakarta.json.stream.JsonGenerator generator)
private void
writeValue(Class<?> type, boolean dynamic, boolean primitive, boolean array, boolean collection, boolean map, Adapter itemConverter, String key, Object value, ObjectConverter.Writer objectConverter, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer, jakarta.json.stream.JsonGenerator generator)
private void
writeWithObjectConverter(DynamicMappingGenerator generator, ObjectConverter.Writer objectConverter, Object value)
-
-
-
Field Detail
-
config
private final MapperConfig config
-
generator
private final jakarta.json.stream.JsonGenerator generator
-
mappings
private final Mappings mappings
-
-
Constructor Detail
-
MappingGeneratorImpl
MappingGeneratorImpl(MapperConfig config, jakarta.json.stream.JsonGenerator jsonGenerator, Mappings mappings)
-
-
Method Detail
-
getJsonGenerator
public jakarta.json.stream.JsonGenerator getJsonGenerator()
- Specified by:
getJsonGenerator
in interfaceMappingGenerator
- Returns:
- the
JsonGenerator
used internally to write the JSON output.
-
writeObject
public MappingGenerator writeObject(String key, Object object, jakarta.json.stream.JsonGenerator generator)
- Specified by:
writeObject
in interfaceMappingGenerator
-
writeObject
public MappingGenerator writeObject(Object object, jakarta.json.stream.JsonGenerator generator)
Description copied from interface:MappingGenerator
Write the given Object o into the current JSON layer. This will not open a new json layer ('{', '}') but really just write the attributes of o to the currently opened layer. Consider you have a classpublic class Customer { private String firstName; private String lastName; private Address address; ... }
then the resulting JSON String will e.g. look like"firstName":"Karl", "lastName":"SomeName", "address":{"street":"mystreet"}
- Specified by:
writeObject
in interfaceMappingGenerator
- Parameters:
object
- the object to writegenerator
- the jsonp generator to use- Returns:
- itself, for easier chaining of commands
-
isDedup
private boolean isDedup()
-
doWriteObject
public void doWriteObject(Object object, jakarta.json.stream.JsonGenerator generator, boolean writeBody, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
-
writeMapBody
private jakarta.json.stream.JsonGenerator writeMapBody(Map<?,?> object, Adapter itemConverter) throws InvocationTargetException, IllegalAccessException
-
writePrimitives
private boolean writePrimitives(Object value)
- Returns:
true
if it was a primitive,false
if the value did not get handled
-
writePrimitives
private boolean writePrimitives(String key, Class<?> type, Object value, jakarta.json.stream.JsonGenerator generator)
-
isInt
private static boolean isInt(Class<?> type)
-
isFloat
private static boolean isFloat(Class<?> type)
-
doWriteObjectBody
private boolean doWriteObjectBody(Object object, Collection<String> ignored, JsonPointerTracker jsonPointer, jakarta.json.stream.JsonGenerator generator) throws IllegalAccessException, InvocationTargetException
-
writeValue
private void writeValue(Class<?> type, boolean dynamic, boolean primitive, boolean array, boolean collection, boolean map, Adapter itemConverter, String key, Object value, ObjectConverter.Writer objectConverter, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer, jakarta.json.stream.JsonGenerator generator) throws InvocationTargetException, IllegalAccessException
-
writeWithObjectConverter
private void writeWithObjectConverter(DynamicMappingGenerator generator, ObjectConverter.Writer objectConverter, Object value)
-
writeIterator
private void writeIterator(Adapter itemConverter, String key, ObjectConverter.Writer objectConverter, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer, jakarta.json.stream.JsonGenerator generator, Iterator<?> iterator, Object originalValue)
-
writeArray
private void writeArray(Class<?> type, Adapter itemConverter, String key, Object arrayValue, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
Write a JSON Array with a given Array Value, like byte[], int[], Person[] etc.- Parameters:
key
- either the attribute key ornull
if the array should be rendered without key
-
writeItem
private void writeItem(Object o, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
-
doWriteIterable
private <T> void doWriteIterable(Iterable<T> object, Collection<String> ignoredProperties, JsonPointerTracker jsonPointer)
-
isInJsRange
private boolean isInJsRange(Number longValue)
-
-