public interface SimpleMapper
A mapper for mapping to basic Java types.
This supports the basic Java types of String, Boolean, Integer, Long, Double and Maps and List of these.
For full support with more types and binding to custom types use avaje-jsonb instead.
Example
static final SimpleMapper simpleMapper = SimpleMapper.builder().build();
Map<String, Long> map = new LinkedHashMap<>();
map.put("one", 45L);
map.put("two", 93L);
String asJson = simpleMapper.toJson(map);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuild the JsonNodeMapper.static interfaceReading and writing with all options such and InputStream, Reader etc. -
Method Summary
Modifier and TypeMethodDescriptionstatic SimpleMapper.Builderbuilder()Create a new builder for SimpleMapper.Read the object from JSON string.fromJsonArray(String json) Read a List from JSON ARRAY string.fromJsonObject(String json) Read a Map from JSON OBJECT string.list()Return a mapper for json ARRAY content with more reading/writing options.map()Return a mapper for json OBJECT content with more reading/writing options.object()Return a mapper for any json content.properties(String... names) Return the property names as PropertyNames.Write the object to JSON string.<T> SimpleMapper.Type<T> type(JsonAdapter<T> customAdapter) Return a Type specific mapper for the given JsonAdapter.
-
Method Details
-
builder
Create a new builder for SimpleMapper. -
object
SimpleMapper.Type<Object> object()Return a mapper for any json content. -
map
SimpleMapper.Type<Map<String,Object>> map()Return a mapper for json OBJECT content with more reading/writing options. -
list
SimpleMapper.Type<List<Object>> list()Return a mapper for json ARRAY content with more reading/writing options. -
toJson
Write the object to JSON string.For options to write json content to OutputStream, Writer etc use
SimpleMapper.Type.var list = List.of(42, "hello"); var asJson = mapper.toJson(list); -
fromJson
Read the object from JSON string. -
fromJsonObject
Read a Map from JSON OBJECT string.Use
map()for more reading options. -
fromJsonArray
Read a List from JSON ARRAY string.Use
list()for more reading options. -
properties
Return the property names as PropertyNames.Provides the option of optimising the writing of json for property names by having them already escaped and encoded rather than as plain strings.
-
type
Return a Type specific mapper for the given JsonAdapter.- Type Parameters:
T- The type of the class to map to/from json.- Parameters:
customAdapter- The custom adapter to use.- Returns:
- The Type specific mapper.
-