ENTITY
- Entity typepublic final class JsonEncoder<ENTITY> extends Object implements Encoder<ENTITY,JsonEncoder<ENTITY>,String>
Modifier and Type | Field and Description |
---|---|
protected Map<String,Function<ENTITY,String>> |
getters |
Constructor and Description |
---|
JsonEncoder(Speedment speedment)
Constructs an empty JsonEncoder with no fields added to the output
renderer.
|
Modifier and Type | Method and Description |
---|---|
static <ENTITY> JsonEncoder<ENTITY> |
allOf(Manager<ENTITY> manager)
Creates and return a new JsonEncoder with all the Entity fields added to
the renderer.
|
String |
apply(ENTITY entity) |
protected static String |
jsonField(Speedment speedment,
FieldIdentifier<?> identifier) |
static String |
jsonValue(Object in) |
static <ENTITY> JsonEncoder<ENTITY> |
noneOf(Manager<ENTITY> manager)
Creates and return a new JsonEncoder with no fields added to the
renderer.
|
static <ENTITY> JsonEncoder<ENTITY> |
of(Manager<ENTITY> manager,
FieldTrait... fields)
Creates and return a new JsonEncoder with the provided Entity field(s)
added to the renderer.
|
<D,T,I extends FieldTrait & ReferenceFieldTrait<ENTITY,D,T>> |
put(I field)
Adds this Field to the output renderer.
|
<D,T,FK_ENTITY,I extends FieldTrait & ReferenceFieldTrait<ENTITY,D,T> & ReferenceForeignKeyFieldTrait<ENTITY,D,FK_ENTITY>> |
put(I field,
Encoder<FK_ENTITY,?,String> builder)
Adds this ReferenceForeignKeyField to the output renderer.
|
<FK_ENTITY> |
put(String label,
Function<ENTITY,FK_ENTITY> getter,
Encoder<FK_ENTITY,?,String> builder)
Adds a field that corresponds to the label to the output renderer.
|
<T> JsonEncoder<ENTITY> |
put(String label,
Function<ENTITY,T> getter)
Adds a field that corresponds to the label to the output renderer.
|
<FK_ENTITY> |
putStreamer(String label,
Function<ENTITY,Stream<FK_ENTITY>> streamer,
Encoder<FK_ENTITY,?,String> builder)
Adds a field that corresponds to the label to the output renderer.
|
<FK_ENTITY> |
putStreamer(String label,
Function<ENTITY,Stream<FK_ENTITY>> streamer,
Function<FK_ENTITY,String> encoder)
Adds a field that corresponds to the label to the output renderer.
|
JsonEncoder<ENTITY> |
remove(FieldTrait field)
Removes this Field from the output renderer.
|
JsonEncoder<ENTITY> |
remove(String label)
Removes the field that corresponds to the provided label from the output
renderer.
|
public JsonEncoder(Speedment speedment)
speedment
- context to usepublic <D,T,I extends FieldTrait & ReferenceFieldTrait<ENTITY,D,T>> JsonEncoder<ENTITY> put(I field)
Encoder
public <D,T,FK_ENTITY,I extends FieldTrait & ReferenceFieldTrait<ENTITY,D,T> & ReferenceForeignKeyFieldTrait<ENTITY,D,FK_ENTITY>> JsonEncoder<ENTITY> put(I field, Encoder<FK_ENTITY,?,String> builder)
Encoder
put
in interface Encoder<ENTITY,JsonEncoder<ENTITY>,String>
D
- the database typeT
- the mapped Java type of the FieldFK_ENTITY
- the mapped Java type of the foreign key FieldI
- Field typefield
- to add to the rendererbuilder
- the foreign key encoderpublic <T> JsonEncoder<ENTITY> put(String label, Function<ENTITY,T> getter)
Encoder
Object
of type T by applying the
provided getter on the Entity and then feeding the returned value to the
default class renderer.public <FK_ENTITY> JsonEncoder<ENTITY> put(String label, Function<ENTITY,FK_ENTITY> getter, Encoder<FK_ENTITY,?,String> builder)
Encoder
put
in interface Encoder<ENTITY,JsonEncoder<ENTITY>,String>
FK_ENTITY
- the mapped Java type of an Entitylabel
- the name of the field to add to the output renderergetter
- fkFormatter the foreign key encoderbuilder
- the foreign key encoderpublic <FK_ENTITY> JsonEncoder<ENTITY> putStreamer(String label, Function<ENTITY,Stream<FK_ENTITY>> streamer, Encoder<FK_ENTITY,?,String> builder)
Encoder
Stream
of type FK_ENTITY from an ENTITY. Each Stream
element will then be rendered in a subarray by applying the provided
fkFormatter.putStreamer
in interface Encoder<ENTITY,JsonEncoder<ENTITY>,String>
FK_ENTITY
- the mapped Java type of an Entitylabel
- the name of the field to add to the output rendererstreamer
- that can produce a Stream<FK_ENTITY>
from an
ENTITY
builder
- the foreign key encoderpublic <FK_ENTITY> JsonEncoder<ENTITY> putStreamer(String label, Function<ENTITY,Stream<FK_ENTITY>> streamer, Function<FK_ENTITY,String> encoder)
Encoder
Stream<FK_ENTITY>
from an ENTITY. Each Stream element
will then be rendered by the provided custom fkMapper that produces an
Object that is subsequently rendered using its default class renderer.putStreamer
in interface Encoder<ENTITY,JsonEncoder<ENTITY>,String>
FK_ENTITY
- the mapped Java type of an Entitylabel
- the name of the field to add to the output rendererstreamer
- that can produce a Stream<FK_ENTITY>
from an
ENTITY
encoder
- the foreign key encoderpublic JsonEncoder<ENTITY> remove(String label)
Encoder
public JsonEncoder<ENTITY> remove(FieldTrait field)
Encoder
protected static String jsonField(Speedment speedment, FieldIdentifier<?> identifier)
public static <ENTITY> JsonEncoder<ENTITY> noneOf(Manager<ENTITY> manager)
ENTITY
- the Entity typemanager
- of the entitypublic static <ENTITY> JsonEncoder<ENTITY> allOf(Manager<ENTITY> manager)
ENTITY
- the Entity typemanager
- of the entity@SafeVarargs public static <ENTITY> JsonEncoder<ENTITY> of(Manager<ENTITY> manager, FieldTrait... fields)
ENTITY
- the Entity typemanager
- of the ENTITYfields
- to add to the output rendererCopyright © 2016 Speedment, Inc.. All rights reserved.