mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#280 - ENH: Add ServerConfig.setJsonInclude(...) ALL, NON_NULL, NON_EMPTY
This commit is contained in:
@@ -26,4 +26,22 @@ public abstract class JsonConfig {
|
||||
ISO8601
|
||||
}
|
||||
|
||||
|
||||
public enum Include {
|
||||
|
||||
/**
|
||||
* Include all values including null and empty collections.
|
||||
*/
|
||||
ALL,
|
||||
|
||||
/**
|
||||
* Exclude null values (include empty collections).
|
||||
*/
|
||||
NON_NULL,
|
||||
|
||||
/**
|
||||
* Exclude null values and empty collections.
|
||||
*/
|
||||
NON_EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,12 @@ public class ServerConfig {
|
||||
*/
|
||||
private JsonConfig.DateTime jsonDateTime = JsonConfig.DateTime.MILLIS;
|
||||
|
||||
/**
|
||||
* For writing JSON specify if null values or empty collections should be exluded.
|
||||
* By default all values are included.
|
||||
*/
|
||||
private JsonConfig.Include jsonInclude = JsonConfig.Include.ALL;
|
||||
|
||||
/**
|
||||
* The database platform name. Used to imply a DatabasePlatform to use.
|
||||
*/
|
||||
@@ -304,7 +310,7 @@ public class ServerConfig {
|
||||
/**
|
||||
* Return the Jackson JsonFactory to use.
|
||||
* <p>
|
||||
* If not set a default implmentation will be used.
|
||||
* If not set a default implementation will be used.
|
||||
*/
|
||||
public JsonFactory getJsonFactory() {
|
||||
return jsonFactory;
|
||||
@@ -313,7 +319,7 @@ public class ServerConfig {
|
||||
/**
|
||||
* Set the Jackson JsonFactory to use.
|
||||
* <p>
|
||||
* If not set a default implmentation will be used.
|
||||
* If not set a default implementation will be used.
|
||||
*/
|
||||
public void setJsonFactory(JsonFactory jsonFactory) {
|
||||
this.jsonFactory = jsonFactory;
|
||||
@@ -333,6 +339,23 @@ public class ServerConfig {
|
||||
this.jsonDateTime = jsonDateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSON include mode used when writing JSON.
|
||||
*/
|
||||
public JsonConfig.Include getJsonInclude() {
|
||||
return jsonInclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the JSON include mode used when writing JSON.
|
||||
* <p>
|
||||
* Set to NON_NULL or NON_EMPTY to suppress nulls or null & empty collections respectively.
|
||||
* </p>
|
||||
*/
|
||||
public void setJsonInclude(JsonConfig.Include jsonInclude) {
|
||||
this.jsonInclude = jsonInclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the EbeanServer.
|
||||
*/
|
||||
@@ -1784,7 +1807,7 @@ public class ServerConfig {
|
||||
int batchSize = p.getInt("batch.size", persistBatchSize);
|
||||
persistBatchSize = p.getInt("persistBatchSize", batchSize);
|
||||
|
||||
persistenceContextScope = PersistenceContextScope.valueOf(p.get("persistenceContextScope","TRANSACTION"));
|
||||
persistenceContextScope = PersistenceContextScope.valueOf(p.get("persistenceContextScope", "TRANSACTION"));
|
||||
|
||||
dataSourceJndiName = p.get("dataSourceJndiName", dataSourceJndiName);
|
||||
databaseSequenceBatchSize = p.getInt("databaseSequenceBatchSize", databaseSequenceBatchSize);
|
||||
@@ -1797,6 +1820,7 @@ public class ServerConfig {
|
||||
lazyLoadBatchSize = p.getInt("lazyLoadBatchSize", lazyLoadBatchSize);
|
||||
queryBatchSize = p.getInt("queryBatchSize", queryBatchSize);
|
||||
|
||||
jsonInclude = p.getEnum(JsonConfig.Include.class, "jsonInclude", jsonInclude);
|
||||
String jsonDateTimeFormat = p.get("jsonDateTime", null);
|
||||
if (jsonDateTimeFormat != null) {
|
||||
jsonDateTime = JsonConfig.DateTime.valueOf(jsonDateTimeFormat);
|
||||
|
||||
@@ -163,8 +163,6 @@ public interface JsonContext {
|
||||
/**
|
||||
* Deprecated in favour of using PathProperties by itself.
|
||||
* Write json to the JsonGenerator using the JsonWriteOptions.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
void toJson(Object value, JsonGenerator generator, JsonWriteOptions options) throws JsonIOException;
|
||||
|
||||
@@ -173,7 +171,6 @@ public interface JsonContext {
|
||||
* With additional options.
|
||||
*
|
||||
* @throws JsonIOException When IOException occurs
|
||||
* @deprecated
|
||||
*/
|
||||
void toJson(Object value, Writer writer, JsonWriteOptions options) throws JsonIOException;
|
||||
|
||||
@@ -182,7 +179,6 @@ public interface JsonContext {
|
||||
* Convert a bean or collection to json string.
|
||||
*
|
||||
* @throws JsonIOException When IOException occurs
|
||||
* @deprecated
|
||||
*/
|
||||
String toJson(Object value, JsonWriteOptions options) throws JsonIOException;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebean.text.json;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
|
||||
/**
|
||||
@@ -15,6 +16,8 @@ public class JsonWriteOptions {
|
||||
|
||||
protected Object objectMapper;
|
||||
|
||||
protected JsonConfig.Include include;
|
||||
|
||||
/**
|
||||
* Parse and return a PathProperties from nested string format like
|
||||
* (a,b,c(d,e),f(g)) where "c" is a path containing "d" and "e" and "f" is a
|
||||
@@ -50,6 +53,20 @@ public class JsonWriteOptions {
|
||||
return pathProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the include mode for this request.
|
||||
*/
|
||||
public JsonConfig.Include getInclude() {
|
||||
return include;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the include mode for this request.
|
||||
*/
|
||||
public void setInclude(JsonConfig.Include include) {
|
||||
this.include = include;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the jackson object mapper to use.
|
||||
* <p/>
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
@@ -141,11 +140,13 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
list = (List<?>) collection;
|
||||
}
|
||||
|
||||
ctx.writeStartArray(name);
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) list.get(j));
|
||||
if (!list.isEmpty() || ctx.isIncludeEmpty()) {
|
||||
ctx.writeStartArray(name);
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) list.get(j));
|
||||
}
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -177,12 +177,14 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
map = (Map<?, ?>) collection;
|
||||
}
|
||||
|
||||
ctx.writeStartArray(name);
|
||||
for (Entry<?, ?> entry : map.entrySet()) {
|
||||
//FIXME: json write map key ...
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) entry.getValue());
|
||||
if (!map.isEmpty() || ctx.isIncludeEmpty()) {
|
||||
ctx.writeStartArray(name);
|
||||
for (Entry<?, ?> entry : map.entrySet()) {
|
||||
//FIXME: json write map key ...
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) entry.getValue());
|
||||
}
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1074,10 +1074,10 @@ public class BeanProperty implements ElPropertyValue {
|
||||
}
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
writeJson.writeNull(name);
|
||||
writeJson.writeNullField(name);
|
||||
} else {
|
||||
if (scalarType != null) {
|
||||
scalarType.jsonWrite(writeJson.gen(), name, value);
|
||||
scalarType.jsonWrite(writeJson, name, value);
|
||||
} else {
|
||||
writeJson.writeValueUsingObjectMapper(name, value);
|
||||
}
|
||||
|
||||
@@ -876,7 +876,10 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
if (isTransient) {
|
||||
ctx.writeValueUsingObjectMapper(name, value);
|
||||
} else {
|
||||
ctx.toJson(name, (Collection<?>) value);
|
||||
Collection<?> collection = (Collection<?>)value;
|
||||
if (!collection.isEmpty() || ctx.isIncludeEmpty()) {
|
||||
ctx.toJson(name, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.popParentBeanMany();
|
||||
|
||||
@@ -830,7 +830,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
writeJson.writeNull(name);
|
||||
writeJson.writeNullField(name);
|
||||
|
||||
} else {
|
||||
if (writeJson.isParentBean(value)) {
|
||||
|
||||
@@ -171,7 +171,7 @@ public class BeanPropertyCompound extends BeanProperty {
|
||||
}
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
ctx.writeNull(name);
|
||||
ctx.writeNullField(name);
|
||||
} else {
|
||||
compoundType.jsonWrite(ctx, value, name);
|
||||
}
|
||||
|
||||
@@ -139,11 +139,13 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
set = (Set<?>) collection;
|
||||
}
|
||||
|
||||
ctx.writeStartArray(name);
|
||||
Iterator<?> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) it.next());
|
||||
if (!set.isEmpty() || ctx.isIncludeEmpty()) {
|
||||
ctx.writeStartArray(name);
|
||||
Iterator<?> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) it.next());
|
||||
}
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.json.*;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -26,10 +27,13 @@ public class DJsonContext implements JsonContext {
|
||||
|
||||
private final Object defaultObjectMapper;
|
||||
|
||||
private final JsonConfig.Include defaultInclude;
|
||||
|
||||
public DJsonContext(SpiEbeanServer server, JsonFactory jsonFactory) {
|
||||
this.server = server;
|
||||
this.jsonFactory = (jsonFactory != null) ? jsonFactory : new JsonFactory();
|
||||
this.defaultObjectMapper = this.server.getServerConfig().getObjectMapper();
|
||||
this.defaultInclude = this.server.getServerConfig().getJsonInclude();
|
||||
}
|
||||
|
||||
public boolean isSupportedType(Type genericType) {
|
||||
@@ -274,7 +278,7 @@ public class DJsonContext implements JsonContext {
|
||||
|
||||
private WriteJson createWriteJson(JsonGenerator gen, JsonWriteOptions options) {
|
||||
PathProperties pathProps = (options == null) ? null : options.getPathProperties();
|
||||
return new WriteJson(server, gen, pathProps, determineObjectMapper(options));
|
||||
return new WriteJson(server, gen, pathProps, determineObjectMapper(options), determineInclude(options));
|
||||
}
|
||||
|
||||
private <T> void toJsonFromCollection(Collection<T> collection, String key, JsonGenerator gen, JsonWriteOptions options) throws IOException {
|
||||
@@ -355,4 +359,15 @@ public class DJsonContext implements JsonContext {
|
||||
Object mapper = options.getObjectMapper();
|
||||
return (mapper != null) ? mapper : defaultObjectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the include mode to use for a JSON write request.
|
||||
*/
|
||||
private JsonConfig.Include determineInclude(JsonWriteOptions options) {
|
||||
if (options == null) {
|
||||
return defaultInclude;
|
||||
}
|
||||
JsonConfig.Include include = options.getInclude();
|
||||
return (include != null) ? include : defaultInclude;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.type.JsonWriter;
|
||||
import com.avaje.ebeaninternal.server.util.ArrayStack;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class WriteJson {
|
||||
public class WriteJson implements JsonWriter {
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
@@ -27,17 +32,105 @@ public class WriteJson {
|
||||
|
||||
private final Object objectMapper;
|
||||
|
||||
public WriteJson(SpiEbeanServer server, JsonGenerator generator, PathProperties pathProperties, Object objectMapper){
|
||||
private final JsonConfig.Include include;
|
||||
|
||||
public WriteJson(SpiEbeanServer server, JsonGenerator generator, PathProperties pathProperties, Object objectMapper, JsonConfig.Include include){
|
||||
this.server = server;
|
||||
this.generator = generator;
|
||||
this.pathProperties = pathProperties;
|
||||
this.objectMapper = objectMapper;
|
||||
this.include = include;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct for testing purposes only.
|
||||
*/
|
||||
public WriteJson(JsonGenerator generator, JsonConfig.Include include) {
|
||||
this(null, generator, null, null, include);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if null values should be included in JSON output.
|
||||
*/
|
||||
public boolean isIncludeNull() {
|
||||
return include == JsonConfig.Include.ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if empty collections should be included in the JSON output.
|
||||
*/
|
||||
public boolean isIncludeEmpty() {
|
||||
return include != JsonConfig.Include.NON_EMPTY;
|
||||
}
|
||||
|
||||
public JsonGenerator gen() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeFieldName(String name) throws IOException {
|
||||
generator.writeFieldName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNullField(String name) throws IOException {
|
||||
if (isIncludeNull()) {
|
||||
generator.writeNullField(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNumberField(String name, Long value) throws IOException {
|
||||
generator.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNumberField(String name, Double value) throws IOException {
|
||||
generator.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNumberField(String name, int value) throws IOException {
|
||||
generator.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNumberField(String name, Short value) throws IOException {
|
||||
generator.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeNumberField(String name, Float value) throws IOException {
|
||||
generator.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeNumberField(String name, BigDecimal value) throws IOException {
|
||||
generator.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStringField(String name, String value) throws IOException {
|
||||
generator.writeStringField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBinary(InputStream is, int length) throws IOException {
|
||||
generator.writeBinary(is, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBinaryField(String name, byte[] value) throws IOException {
|
||||
generator.writeBinaryField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBooleanField(String name, Boolean value) throws IOException {
|
||||
generator.writeBooleanField(name, value);
|
||||
}
|
||||
|
||||
public boolean isParentBean(Object bean) {
|
||||
return !parentBeans.isEmpty() && parentBeans.contains(bean);
|
||||
}
|
||||
@@ -78,6 +171,17 @@ public class WriteJson {
|
||||
}
|
||||
|
||||
public void writeValueUsingObjectMapper(String name, Object value) throws IOException {
|
||||
|
||||
if (!isIncludeEmpty()) {
|
||||
// check for suppression of empty collection or map
|
||||
if (value instanceof Collection && ((Collection)value).isEmpty()) {
|
||||
// suppress empty collection
|
||||
return;
|
||||
} else if (value instanceof Map && ((Map)value).isEmpty()) {
|
||||
// suppress empty map
|
||||
return;
|
||||
}
|
||||
}
|
||||
generator.writeFieldName(name);
|
||||
objectMapper().writeValue(generator, value);
|
||||
}
|
||||
@@ -215,10 +319,6 @@ public class WriteJson {
|
||||
}
|
||||
generator.writeStartObject();
|
||||
}
|
||||
|
||||
public void writeNull(String name) throws IOException {
|
||||
generator.writeNullField(name);
|
||||
}
|
||||
|
||||
public void writeEndObject() throws IOException {
|
||||
generator.writeEndObject();
|
||||
|
||||
@@ -197,7 +197,7 @@ public final class CtCompoundType<V> implements ScalarDataReader<V> {
|
||||
((CtCompoundType) propReaders[i]).jsonWrite(ctx, value, propName);
|
||||
|
||||
} else {
|
||||
((ScalarType) propReaders[i]).jsonWrite(ctx.gen(), propName, value);
|
||||
((ScalarType) propReaders[i]).jsonWrite(ctx, propName, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Wraps an underlying JsonGenerator taking into account null suppression and exposing isIncludeEmpty() etc.
|
||||
*/
|
||||
public interface JsonWriter {
|
||||
|
||||
/**
|
||||
* Return the Jackson core JsonGenerator.
|
||||
*/
|
||||
JsonGenerator gen();
|
||||
|
||||
/**
|
||||
* Return true if null values should be included in JSON output.
|
||||
*/
|
||||
boolean isIncludeNull();
|
||||
|
||||
/**
|
||||
* Return true if empty collections should be included in the JSON output.
|
||||
*/
|
||||
boolean isIncludeEmpty();
|
||||
|
||||
/**
|
||||
* Write the field name.
|
||||
*/
|
||||
void writeFieldName(String name) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a null value taking into account null value suppression.
|
||||
*/
|
||||
void writeNullField(String name) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a number field.
|
||||
*/
|
||||
void writeNumberField(String name, int value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a number field.
|
||||
*/
|
||||
void writeNumberField(String name, Short value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a number field.
|
||||
*/
|
||||
void writeNumberField(String name, Long value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a number field.
|
||||
*/
|
||||
void writeNumberField(String name, Double value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a number field.
|
||||
*/
|
||||
void writeNumberField(String name, Float value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a number field.
|
||||
*/
|
||||
void writeNumberField(String name, BigDecimal value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a sting field.
|
||||
*/
|
||||
void writeStringField(String name, String value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a binary field.
|
||||
*/
|
||||
void writeBinary(InputStream is, int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a binary field.
|
||||
*/
|
||||
void writeBinaryField(String name, byte[] value) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a boolean field.
|
||||
*/
|
||||
void writeBooleanField(String name, Boolean value) throws IOException;
|
||||
}
|
||||
@@ -202,6 +202,6 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
/**
|
||||
* Write the value to the JsonGenerator.
|
||||
*/
|
||||
void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException;
|
||||
void jsonWrite(JsonWriter writer, String name, T value) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -77,9 +77,9 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, T value) throws IOException {
|
||||
long millis = convertToMillis(value);
|
||||
ctx.writeNumberField(name, millis);
|
||||
writer.writeNumberField(name, millis);
|
||||
}
|
||||
|
||||
public T readData(DataInput dataInput) throws IOException {
|
||||
|
||||
@@ -103,21 +103,21 @@ public abstract class ScalarTypeBaseDateTime<T> extends ScalarTypeBase<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator generator, String name, T value) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, T value) throws IOException {
|
||||
|
||||
switch (mode) {
|
||||
case ISO8601: {
|
||||
generator.writeFieldName(name);
|
||||
generator.writeString(toJsonISO8601(value));
|
||||
writer.writeFieldName(name);
|
||||
writer.gen().writeString(toJsonISO8601(value));
|
||||
break;
|
||||
}
|
||||
case NANOS: {
|
||||
generator.writeFieldName(name);
|
||||
generator.writeNumber(toJsonNanos(value));
|
||||
writer.writeFieldName(name);
|
||||
writer.gen().writeNumber(toJsonNanos(value));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
generator.writeNumberField(name, convertToMillis(value));
|
||||
writer.gen().writeNumberField(name, convertToMillis(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public abstract class ScalarTypeBaseVarchar<T> extends ScalarTypeBase<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
|
||||
ctx.writeStringField(name, format(value));
|
||||
public void jsonWrite(JsonWriter writer, String name, T value) throws IOException {
|
||||
writer.writeStringField(name, format(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ public class ScalarTypeBigDecimal extends ScalarTypeBase<BigDecimal> {
|
||||
return ctx.getDecimalValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, BigDecimal value) throws IOException {
|
||||
ctx.writeNumberField(name, value);
|
||||
@Override
|
||||
public void jsonWrite(JsonWriter writer, String name, BigDecimal value) throws IOException {
|
||||
writer.writeNumberField(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -284,8 +284,9 @@ public class ScalarTypeBoolean {
|
||||
return JsonToken.VALUE_TRUE == event ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Boolean value) throws IOException {
|
||||
ctx.writeBooleanField(name, value);
|
||||
@Override
|
||||
public void jsonWrite(JsonWriter writer, String name, Boolean value) throws IOException {
|
||||
writer.writeBooleanField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ScalarTypeByte extends ScalarTypeBase<Byte> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Byte value) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, Byte value) throws IOException {
|
||||
throw new IOException("Not supported");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ public abstract class ScalarTypeBytesBase extends ScalarTypeBase<byte[]> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, byte[] value) throws IOException {
|
||||
ctx.writeBinaryField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, byte[] value) throws IOException {
|
||||
writer.writeBinaryField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,8 +64,8 @@ public class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, byte[] value) throws IOException {
|
||||
ctx.writeBinaryField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, byte[] value) throws IOException {
|
||||
writer.writeBinaryField(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ScalarTypeDouble extends ScalarTypeBase<Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Double value) throws IOException {
|
||||
ctx.writeNumberField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, Double value) throws IOException {
|
||||
writer.writeNumberField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ScalarTypeDuration extends ScalarTypeBase<Duration> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Duration value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
public void jsonWrite(JsonWriter writer, String name, Duration value) throws IOException {
|
||||
writer.writeStringField(name, value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
|
||||
wrapped.jsonWrite(ctx, name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, T value) throws IOException {
|
||||
wrapped.jsonWrite(writer, name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,8 +237,8 @@ public class ScalarTypeEnumStandard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, formatValue(value));
|
||||
public void jsonWrite(JsonWriter writer, String name, Object value) throws IOException {
|
||||
writer.writeStringField(name, formatValue(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -102,10 +102,10 @@ public class ScalarTypeFile extends ScalarTypeBase<File> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, File value) throws IOException {
|
||||
ctx.writeFieldName(name);
|
||||
public void jsonWrite(JsonWriter writer, String name, File value) throws IOException {
|
||||
writer.writeFieldName(name);
|
||||
InputStream is = getInputStream(value);
|
||||
ctx.writeBinary(is, (int) value.length());
|
||||
writer.writeBinary(is, (int) value.length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ScalarTypeFloat extends ScalarTypeBase<Float> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Float value) throws IOException {
|
||||
ctx.writeNumberField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, Float value) throws IOException {
|
||||
writer.writeNumberField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ScalarTypeInteger extends ScalarTypeBase<Integer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Integer value) throws IOException {
|
||||
ctx.writeNumberField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, Integer value) throws IOException {
|
||||
writer.writeNumberField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ public class ScalarTypeJodaLocalTime extends ScalarTypeBase<LocalTime> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, LocalTime value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
public void jsonWrite(JsonWriter writer, String name, LocalTime value) throws IOException {
|
||||
writer.writeStringField(name, value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -193,13 +193,15 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase<Map> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Map value) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, Map value) throws IOException {
|
||||
// write the field name followed by the Map/JSON Object
|
||||
if (value == null) {
|
||||
ctx.writeNullField(name);
|
||||
writer.writeNullField(name);
|
||||
} else {
|
||||
ctx.writeFieldName(name);
|
||||
EJson.write(value, ctx);
|
||||
if (!value.isEmpty() || writer.isIncludeEmpty()) {
|
||||
writer.writeFieldName(name);
|
||||
EJson.write(value, writer.gen());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,13 +207,13 @@ public abstract class ScalarTypeJsonNode extends ScalarTypeBase<JsonNode> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, JsonNode value) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, JsonNode value) throws IOException {
|
||||
// write the field name followed by the JsonNode object
|
||||
if (value == null) {
|
||||
ctx.writeNullField(name);
|
||||
writer.writeNullField(name);
|
||||
} else {
|
||||
ctx.writeFieldName(name);
|
||||
objectMapper.writeTree(ctx, value);
|
||||
writer.writeFieldName(name);
|
||||
objectMapper.writeTree(writer.gen(), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ScalarTypeLocalTime extends ScalarTypeBase<LocalTime> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, LocalTime value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
public void jsonWrite(JsonWriter writer, String name, LocalTime value) throws IOException {
|
||||
writer.writeStringField(name, value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ScalarTypeLong extends ScalarTypeBase<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Long value) throws IOException {
|
||||
ctx.writeNumberField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, Long value) throws IOException {
|
||||
writer.writeNumberField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, BigInteger value) throws IOException {
|
||||
ctx.writeNumberField(name, value.longValue());
|
||||
public void jsonWrite(JsonWriter writer, String name, BigInteger value) throws IOException {
|
||||
writer.writeNumberField(name, value.longValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@ public class ScalarTypeMonthDay extends ScalarTypeBase<MonthDay> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, MonthDay value) throws IOException {
|
||||
ctx.writeStringField(name, format(value));
|
||||
public void jsonWrite(JsonWriter writer, String name, MonthDay value) throws IOException {
|
||||
writer.writeStringField(name, format(value));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -112,13 +112,13 @@ public class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Map value) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, Map value) throws IOException {
|
||||
// write the field name followed by the Map/JSON Object
|
||||
if (value == null) {
|
||||
ctx.writeNullField(name);
|
||||
writer.writeNullField(name);
|
||||
} else {
|
||||
ctx.writeFieldName(name);
|
||||
EJson.write(value, ctx);
|
||||
writer.writeFieldName(name);
|
||||
EJson.write(value, writer.gen());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ScalarTypeShort extends ScalarTypeBase<Short> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Short value) throws IOException {
|
||||
ctx.writeNumberField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, Short value) throws IOException {
|
||||
writer.writeNumberField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ScalarTypeString extends ScalarTypeBase<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, String value) throws IOException {
|
||||
ctx.writeStringField(name, value);
|
||||
public void jsonWrite(JsonWriter writer, String name, String value) throws IOException {
|
||||
writer.writeStringField(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ public class ScalarTypeTime extends ScalarTypeBase<Time> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Time value) throws IOException {
|
||||
ctx.writeStringField(name, format(value));
|
||||
public void jsonWrite(JsonWriter writer, String name, Time value) throws IOException {
|
||||
writer.writeStringField(name, format(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ public class ScalarTypeUUIDBinary extends ScalarTypeBase<UUID> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, UUID value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
public void jsonWrite(JsonWriter writer, String name, UUID value) throws IOException {
|
||||
writer.writeStringField(name, value.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -188,9 +188,9 @@ public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, B beanValue) throws IOException {
|
||||
public void jsonWrite(JsonWriter writer, String name, B beanValue) throws IOException {
|
||||
S unwrapValue = converter.unwrapValue(beanValue);
|
||||
scalarType.jsonWrite(ctx, name, unwrapValue);
|
||||
scalarType.jsonWrite(writer, name, unwrapValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ScalarTypeYear extends ScalarTypeBase<Year> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Year value) throws IOException {
|
||||
ctx.writeNumberField(name, value.getValue());
|
||||
public void jsonWrite(JsonWriter writer, String name, Year value) throws IOException {
|
||||
writer.writeNumberField(name, value.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user