public abstract class ToJSON
extends java.lang.Object
A utility class for formatting OData values as JSON strings.
| Constructor and Description |
|---|
ToJSON() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
complex(ComplexValue value)
|
static java.lang.String |
complex(ComplexValue value,
int options)
Format a complex value as a JSON string, including structural and navigation properties.
|
static java.lang.String |
complexList(ComplexValueList value)
|
static java.lang.String |
complexList(ComplexValueList value,
int options)
Format a complex list as a JSON string, including structural and navigation properties.
|
static <C extends ComplexValue> |
complexList(java.util.List<C> value)
Format a generic complex list as a JSON string.
|
static <C extends ComplexValue> |
complexList(java.util.List<C> value,
int options)
Format a generic complex list as a JSON string.
|
static java.lang.String |
dataURI(java.lang.Object value)
Convert
value to OData 4.0 JSON format, then convert to a data URI with media type "application/json" and base64-encoded data. |
static java.lang.String |
entity(EntityValue value)
|
static java.lang.String |
entity(EntityValue value,
int options)
Format an entity value as a JSON string, including structural and navigation properties.
|
static java.lang.String |
entityKey(EntityValue value)
|
static java.lang.String |
entityKey(EntityValue value,
int options)
Format an entity value as a JSON string, including only key properties.
|
static java.lang.String |
entityList(EntityValueList value)
|
static java.lang.String |
entityList(EntityValueList value,
int options)
Format an entity list as a JSON string, including structural and navigation properties.
|
static <E extends EntityValue> |
entityList(java.util.List<E> value)
Format a generic entity list as a JSON string.
|
static <E extends EntityValue> |
entityList(java.util.List<E> value,
int options)
Format a generic entity list as a JSON string.
|
public static <C extends ComplexValue> java.lang.String complexList(java.util.List<C> value)
C - Complex value subclass (e.g. proxy class).value - Complex list.public static <C extends ComplexValue> java.lang.String complexList(java.util.List<C> value, int options)
C - Complex value subclass (e.g. proxy class).value - Complex list.options - Additional bind options.public static <E extends EntityValue> java.lang.String entityList(java.util.List<E> value)
E - Entity value subclass (e.g. proxy class).value - Entity list.public static <E extends EntityValue> java.lang.String entityList(java.util.List<E> value, int options)
E - Entity value subclass (e.g. proxy class).value - Entity list.options - Additional bind options.public static java.lang.String complex(ComplexValue value)
value - Value parameter.public static java.lang.String complex(ComplexValue value, int options)
Format a complex value as a JSON string, including structural and navigation properties.
value - Complex value.options - Additional bind options. See DataContext constants.public static java.lang.String complexList(ComplexValueList value)
value - Value parameter.public static java.lang.String complexList(ComplexValueList value, int options)
Format a complex list as a JSON string, including structural and navigation properties.
value - Complex list.options - Additional bind options. See DataContext constants.public static java.lang.String dataURI(java.lang.Object value)
Convert value to OData 4.0 JSON format, then convert to a data URI with media type "application/json" and base64-encoded data.
value - (nullable) Header value.public static java.lang.String entity(EntityValue value)
value - Value parameter.public static java.lang.String entity(EntityValue value, int options)
Format an entity value as a JSON string, including structural and navigation properties.
public void jsonEntityExample() {
NorthwindService service = this.getService();
Customer customer = new Customer(false);
customer.setCustomerID("123");
customer.setContactName("Four Five Six");
customer.setCompanyName("JSON Inc.");
customer.setOldEntity(customer.copy());
customer.getOld().setContactName("One Two Three");
this.showCustomer(customer);
String json = ToJSON.entity(customer);
Example.show(json);
Customer restoredCustomer = service.getCustomer(FromJSON.entity(json));
this.showCustomer(restoredCustomer);
assert StringOperator.equal(customer.toString(),
restoredCustomer.toString());
assert StringOperator.equal(customer.getOld()
.toString(), restoredCustomer.getOld().toString());
}
value - Entity value.options - Additional bind options. See DataContext constants.public static java.lang.String entityKey(EntityValue value)
value - Value parameter.public static java.lang.String entityKey(EntityValue value, int options)
Format an entity value as a JSON string, including only key properties.
value - Entity value.options - Additional bind options. See DataContext constants.public static java.lang.String entityList(EntityValueList value)
value - Value parameter.public static java.lang.String entityList(EntityValueList value, int options)
Format an entity list as a JSON string, including structural and navigation properties.
value - Entity list.options - Additional bind options. See DataContext constants.