mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Move from javax.json to jackson-core for parser/generator
This commit is contained in:
@@ -1383,10 +1383,17 @@ public final class Ebean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a JsonContext that will use the default configuration options.
|
||||
* Return the JsonContext for reading/writing JSON.
|
||||
*/
|
||||
public static JsonContext json() {
|
||||
return serverMgr.getPrimaryServer().json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JsonContext for reading/writing JSON.
|
||||
*/
|
||||
public static JsonContext createJsonContext() {
|
||||
return serverMgr.getPrimaryServer().createJsonContext();
|
||||
return json();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1119,9 +1119,13 @@ public interface EbeanServer {
|
||||
public void runCacheWarming(Class<?> beanType);
|
||||
|
||||
/**
|
||||
* Create a JsonContext that will use the default configuration options.
|
||||
* Return the JsonContext for reading/writing JSON.
|
||||
*/
|
||||
public JsonContext createJsonContext();
|
||||
|
||||
/**
|
||||
* Return the JsonContext for reading/writing JSON.
|
||||
*/
|
||||
public JsonContext json();
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.avaje.ebean.event.ServerConfigStartup;
|
||||
import com.avaje.ebean.event.TransactionEventListener;
|
||||
import com.avaje.ebean.meta.MetaInfoManager;
|
||||
import com.avaje.ebean.util.ClassUtil;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
|
||||
/**
|
||||
* The configuration used for creating a EbeanServer.
|
||||
@@ -241,6 +242,8 @@ public class ServerConfig {
|
||||
|
||||
private boolean collectQueryOrigins;
|
||||
|
||||
private JsonFactory jsonFactory;
|
||||
|
||||
/**
|
||||
* Construct a Server Configuration for programmatically creating an
|
||||
* EbeanServer.
|
||||
@@ -248,6 +251,24 @@ public class ServerConfig {
|
||||
public ServerConfig() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Jackson JsonFactory to use.
|
||||
* <p>
|
||||
* If not set a default implmentation will be used.
|
||||
*/
|
||||
public JsonFactory getJsonFactory() {
|
||||
return jsonFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Jackson JsonFactory to use.
|
||||
* <p>
|
||||
* If not set a default implmentation will be used.
|
||||
*/
|
||||
public void setJsonFactory(JsonFactory jsonFactory) {
|
||||
this.jsonFactory = jsonFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the EbeanServer.
|
||||
|
||||
@@ -1,78 +1,80 @@
|
||||
package com.avaje.ebean.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
/**
|
||||
* Utility that converts between JSON content and java Maps/Lists.
|
||||
*/
|
||||
public class EJson {
|
||||
|
||||
/**
|
||||
* Write the nested Map/List as json.
|
||||
*/
|
||||
public static String write(Object object) {
|
||||
return EJsonWriter.write(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the nested Map/List as json to the writer.
|
||||
*/
|
||||
public static void write(Object object, Writer writer) {
|
||||
EJsonWriter.write(object, writer);
|
||||
}
|
||||
// /**
|
||||
// * Write the nested Map/List as json.
|
||||
// */
|
||||
// public static String write(Object object) {
|
||||
// return EJsonWriter.write(object);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Write the nested Map/List as json to the writer.
|
||||
// */
|
||||
// public static void write(Object object, Writer writer) {
|
||||
// EJsonWriter.write(object, writer);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Write the nested Map/List as json to the jsonGenerator.
|
||||
*/
|
||||
public static void write(Object object, JsonGenerator jsonGenerator) {
|
||||
public static void write(Object object, JsonGenerator jsonGenerator) throws IOException {
|
||||
EJsonWriter.write(object, jsonGenerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a Map.
|
||||
*/
|
||||
public static Map<String,Object> parseObject(String json) {
|
||||
public static Map<String,Object> parseObject(String json) throws IOException {
|
||||
return EJsonReader.parseObject(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a Map taking a reader.
|
||||
*/
|
||||
public static Map<String,Object> parseObject(Reader reader) {
|
||||
public static Map<String,Object> parseObject(Reader reader) throws IOException {
|
||||
return EJsonReader.parseObject(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a Map taking a JsonParser.
|
||||
*/
|
||||
public static Map<String,Object> parseObject(JsonParser parser) {
|
||||
public static Map<String,Object> parseObject(JsonParser parser) throws IOException {
|
||||
return EJsonReader.parseObject(parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a List.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<Object> parseList(String json) {
|
||||
public static List<Object> parseList(String json) throws IOException {
|
||||
return EJsonReader.parseList(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a List taking a Reader.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<Object> parseList(Reader reader) {
|
||||
public static List<Object> parseList(Reader reader) throws IOException {
|
||||
return EJsonReader.parseList(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a List taking a JsonParser.
|
||||
*/
|
||||
public static List<Object> parseList(JsonParser parser) {
|
||||
public static List<Object> parseList(JsonParser parser) throws IOException {
|
||||
return EJsonReader.parseList(parser);
|
||||
}
|
||||
|
||||
@@ -80,39 +82,39 @@ public class EJson {
|
||||
/**
|
||||
* Parse the json and return as a List or Map.
|
||||
*/
|
||||
public static Object parse(String json) {
|
||||
public static Object parse(String json) throws IOException {
|
||||
return EJsonReader.parse(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a List or Map.
|
||||
*/
|
||||
public static Object parse(Reader reader) {
|
||||
public static Object parse(Reader reader) throws IOException {
|
||||
return EJsonReader.parse(reader, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return as a List or Map.
|
||||
*/
|
||||
public static Object parse(JsonParser parser) {
|
||||
public static Object parse(JsonParser parser) throws IOException {
|
||||
return EJsonReader.parse(parser, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the json and return the next json value, List or Map.
|
||||
* This will not consume all the reader content and return once the
|
||||
* next json object, list or value is read.
|
||||
*/
|
||||
public static Object parsePartial(Reader reader) {
|
||||
return EJsonReader.parse(reader, true);
|
||||
}
|
||||
// /**
|
||||
// * Parse the json and return the next json value, List or Map.
|
||||
// * This will not consume all the reader content and return once the
|
||||
// * next json object, list or value is read.
|
||||
// */
|
||||
// public static Object parsePartial(Reader reader) {
|
||||
// return EJsonReader.parse(reader, true);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Parse the json and return the next json value, List or Map.
|
||||
* This will not consume all the reader content and return once the
|
||||
* next json object, list or value is read.
|
||||
*/
|
||||
public static Object parsePartial(JsonParser parser) {
|
||||
public static Object parsePartial(JsonParser parser) throws IOException {
|
||||
return EJsonReader.parse(parser, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebean.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
@@ -8,57 +9,59 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
class EJsonReader {
|
||||
|
||||
static JsonFactory json = new JsonFactory();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Map<String, Object> parseObject(String json) {
|
||||
static Map<String, Object> parseObject(String json) throws IOException {
|
||||
return (Map<String, Object>) parse(json);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Map<String, Object> parseObject(Reader reader) {
|
||||
static Map<String, Object> parseObject(Reader reader) throws IOException {
|
||||
return (Map<String, Object>) parse(reader, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Map<String, Object> parseObject(JsonParser parser) {
|
||||
static Map<String, Object> parseObject(JsonParser parser) throws IOException {
|
||||
return (Map<String, Object>) parse(parser, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static List<Object> parseList(String json) {
|
||||
static List<Object> parseList(String json) throws IOException {
|
||||
return (List<Object>) parse(json);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static List<Object> parseList(Reader reader) {
|
||||
static List<Object> parseList(Reader reader) throws IOException {
|
||||
return (List<Object>) parse(reader, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static List<Object> parseList(JsonParser parser) {
|
||||
static List<Object> parseList(JsonParser parser) throws IOException {
|
||||
return (List<Object>) parse(parser, false);
|
||||
}
|
||||
|
||||
static Object parse(String json) {
|
||||
static Object parse(String json) throws IOException {
|
||||
return parse(new StringReader(json), false);
|
||||
}
|
||||
|
||||
static Object parse(Reader reader, boolean partial) {
|
||||
return parse(Json.createParser(reader), partial);
|
||||
static Object parse(Reader reader, boolean partial) throws IOException {
|
||||
return parse(json.createParser(reader), partial);
|
||||
}
|
||||
|
||||
static Object parse(JsonParser parser, boolean partial) {
|
||||
static Object parse(JsonParser parser, boolean partial) throws IOException {
|
||||
return new EJsonReader(parser, partial).parseJson();
|
||||
}
|
||||
|
||||
private final JsonParser parser;
|
||||
|
||||
private final boolean partial;
|
||||
//private final boolean partial;
|
||||
|
||||
private int depth;
|
||||
|
||||
@@ -69,7 +72,7 @@ class EJsonReader {
|
||||
|
||||
EJsonReader(JsonParser parser, boolean partial) {
|
||||
this.parser = parser;
|
||||
this.partial = partial;
|
||||
//this.partial = partial;
|
||||
}
|
||||
|
||||
private void startArray() {
|
||||
@@ -113,73 +116,83 @@ class EJsonReader {
|
||||
|
||||
private Object parseJson() {
|
||||
|
||||
if (!parser.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Event event = parser.next();
|
||||
if (Event.VALUE_NULL == event) {
|
||||
// it is just a null value
|
||||
return null;
|
||||
}
|
||||
Object simpleValue = getSimpleValue(event);
|
||||
if (simpleValue != null) {
|
||||
// it is a simple string, number or boolean
|
||||
return simpleValue;
|
||||
}
|
||||
|
||||
stack = new Stack();
|
||||
// it is a object or array, process the first event
|
||||
processEvent(event);
|
||||
|
||||
// process the rest of the object or array
|
||||
while (parser.hasNext()) {
|
||||
processEvent(parser.next());
|
||||
|
||||
if (partial && depth == 0) {
|
||||
// completed the object/array
|
||||
return currentContext.getValue();
|
||||
try {
|
||||
JsonToken token = parser.nextToken();
|
||||
if (JsonToken.VALUE_NULL == token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//// if (jp.nextToken() != JsonToken.START_OBJECT) {
|
||||
//// throw new IOException("Expected data to start with an Object");
|
||||
//// }
|
||||
//// TwitterEntry result = new TwitterEntry();
|
||||
//// // Iterate over object fields:
|
||||
//// while (jp.nextToken() != JsonToken.END_OBJECT) {
|
||||
//// String fieldName = jp.getCurrentName();
|
||||
//// // Let's move to value
|
||||
//// jp.nextToken();
|
||||
////
|
||||
// if (!parser.hasNext()) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Object simpleValue = getSimpleValue(JsonToken);
|
||||
// if (simpleValue != null) {
|
||||
// // it is a simple string, number or boolean
|
||||
// return simpleValue;
|
||||
// }
|
||||
|
||||
return currentContext.getValue();
|
||||
stack = new Stack();
|
||||
// it is a object or array, process the first JsonToken
|
||||
processJsonToken(token);
|
||||
|
||||
// process the rest of the object or array
|
||||
while (depth > 0) {
|
||||
token = parser.nextToken();
|
||||
processJsonToken(token);
|
||||
}
|
||||
|
||||
return currentContext.getValue();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the event is a value rather than object or array.
|
||||
* <p>
|
||||
* If just a value then return that value else return null.
|
||||
*/
|
||||
private Object getSimpleValue(Event event) {
|
||||
|
||||
switch (event) {
|
||||
case VALUE_STRING:
|
||||
return parser.getString();
|
||||
|
||||
case VALUE_NUMBER:
|
||||
if (parser.isIntegralNumber()) {
|
||||
return parser.getLong();
|
||||
} else {
|
||||
return parser.getBigDecimal();
|
||||
}
|
||||
|
||||
case VALUE_TRUE:
|
||||
return Boolean.TRUE;
|
||||
|
||||
case VALUE_FALSE:
|
||||
return Boolean.FALSE;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * See if the JsonToken is a value rather than object or array.
|
||||
// * <p>
|
||||
// * If just a value then return that value else return null.
|
||||
// * @throws IOException
|
||||
// */
|
||||
// private Object getSimpleValue(JsonToken JsonToken) throws IOException {
|
||||
//
|
||||
// switch (JsonToken) {
|
||||
// case VALUE_STRING:
|
||||
// return parser.getValueAsString();
|
||||
//
|
||||
// case VALUE_NUMBER_INT:
|
||||
// return parser.getLongValue();
|
||||
//
|
||||
// case VALUE_NUMBER_FLOAT:
|
||||
// return parser.getDecimalValue();
|
||||
//
|
||||
// case VALUE_TRUE:
|
||||
// return Boolean.TRUE;
|
||||
//
|
||||
// case VALUE_FALSE:
|
||||
// return Boolean.FALSE;
|
||||
//
|
||||
// default:
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Process the event for objects and arrays.
|
||||
* Process the JsonToken for objects and arrays.
|
||||
*/
|
||||
private void processEvent(Event event) {
|
||||
switch (event) {
|
||||
private void processJsonToken(JsonToken token) throws IOException {
|
||||
switch (token) {
|
||||
|
||||
case START_ARRAY:
|
||||
startArray();
|
||||
@@ -189,20 +202,20 @@ class EJsonReader {
|
||||
startObject();
|
||||
break;
|
||||
|
||||
case KEY_NAME:
|
||||
currentContext.setKey(parser.getString());
|
||||
case FIELD_NAME:
|
||||
currentContext.setKey(parser.getCurrentName());
|
||||
break;
|
||||
|
||||
case VALUE_STRING:
|
||||
setValue(parser.getString());
|
||||
setValue(parser.getValueAsString());
|
||||
break;
|
||||
|
||||
case VALUE_NUMBER:
|
||||
if (parser.isIntegralNumber()) {
|
||||
setValue(parser.getLong());
|
||||
} else {
|
||||
setValue(parser.getBigDecimal());
|
||||
}
|
||||
case VALUE_NUMBER_INT:
|
||||
setValue(parser.getLongValue());
|
||||
break;
|
||||
|
||||
case VALUE_NUMBER_FLOAT:
|
||||
setValue(parser.getDecimalValue());
|
||||
break;
|
||||
|
||||
case VALUE_TRUE:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.avaje.ebean.json;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
@@ -10,22 +9,21 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
class EJsonWriter {
|
||||
|
||||
static String write(Object object) {
|
||||
StringWriter writer = new StringWriter(200);
|
||||
write(object, writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
static void write(Object object, Writer writer) {
|
||||
JsonGenerator generator = Json.createGenerator(writer);
|
||||
write(object, generator);
|
||||
generator.close();
|
||||
}
|
||||
// static String write(Object object) {
|
||||
// StringWriter writer = new StringWriter(200);
|
||||
// write(object, writer);
|
||||
// return writer.toString();
|
||||
// }
|
||||
//
|
||||
// static void write(Object object, Writer writer) {
|
||||
// JsonGenerator generator = Json.createGenerator(writer);
|
||||
// write(object, generator);
|
||||
// generator.close();
|
||||
// }
|
||||
|
||||
static void write(Object object, JsonGenerator jsonGenerator) {
|
||||
new EJsonWriter(jsonGenerator).writeJson(object);
|
||||
@@ -43,55 +41,60 @@ class EJsonWriter {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void writeJson(String name, Object object) {
|
||||
if (object == null) {
|
||||
writeNull(name);
|
||||
try {
|
||||
if (object == null) {
|
||||
writeNull(name);
|
||||
|
||||
} else if (object instanceof Map) {
|
||||
writeMap(name, (Map<Object, Object>) object);
|
||||
} else if (object instanceof Map) {
|
||||
writeMap(name, (Map<Object, Object>) object);
|
||||
|
||||
} else if (object instanceof Collection) {
|
||||
writeCollection(name, (Collection<Object>) object);
|
||||
} else if (object instanceof Collection) {
|
||||
writeCollection(name, (Collection<Object>) object);
|
||||
|
||||
} else if (object instanceof Boolean) {
|
||||
writeBoolean(name, (Boolean) object);
|
||||
} else if (object instanceof Boolean) {
|
||||
writeBoolean(name, (Boolean) object);
|
||||
|
||||
} else if (object instanceof Number) {
|
||||
writeNumber(name, (Number) object);
|
||||
} else if (object instanceof Number) {
|
||||
writeNumber(name, (Number) object);
|
||||
|
||||
} else if (object instanceof Date) {
|
||||
writeDate(name, (Date) object);
|
||||
} else if (object instanceof Date) {
|
||||
writeDate(name, (Date) object);
|
||||
|
||||
} else if (object instanceof String) {
|
||||
writeString(name, (String) object);
|
||||
} else if (object instanceof String) {
|
||||
writeString(name, (String) object);
|
||||
|
||||
} else if (object instanceof Map.Entry<?, ?>) {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)object;
|
||||
writeJson(entry.getKey().toString(), entry.getValue());
|
||||
|
||||
} else {
|
||||
writeString(name, object.toString());
|
||||
} else if (object instanceof Map.Entry<?, ?>) {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) object;
|
||||
writeJson(entry.getKey().toString(), entry.getValue());
|
||||
|
||||
} else {
|
||||
writeString(name, object.toString());
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void writeBoolean(String name, Boolean object) {
|
||||
private void writeBoolean(String name, Boolean object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write(object);
|
||||
jsonGenerator.writeBoolean(object);
|
||||
} else {
|
||||
jsonGenerator.write(name, object);
|
||||
jsonGenerator.writeBooleanField(name, object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDate(String name, Date object) {
|
||||
private void writeDate(String name, Date object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write(object.getTime());
|
||||
jsonGenerator.writeNumber(object.getTime());
|
||||
} else {
|
||||
jsonGenerator.write(name, object.getTime());
|
||||
jsonGenerator.writeNumberField(name, object.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeNumber(String name, Number object) {
|
||||
private void writeNumber(String name, Number object) throws IOException {
|
||||
|
||||
|
||||
if (object instanceof Long) {
|
||||
writeLong(name, object);
|
||||
|
||||
@@ -112,94 +115,88 @@ class EJsonWriter {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeGeneralNumber(String name, Number object) {
|
||||
private void writeGeneralNumber(String name, Number object) throws IOException {
|
||||
writeBigDecimal(name, new BigDecimal(object.toString()));
|
||||
}
|
||||
|
||||
private void writeBigDecimal(String name, Number object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write(new BigDecimal(object.toString()));
|
||||
jsonGenerator.writeNumber((BigDecimal) object);
|
||||
} else {
|
||||
jsonGenerator.write(name, new BigDecimal(object.toString()));
|
||||
jsonGenerator.writeNumberField(name, (BigDecimal) object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeBigDecimal(String name, Number object) {
|
||||
private void writeBigInteger(String name, Number object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write((BigDecimal) object);
|
||||
jsonGenerator.writeNumber((BigInteger) object);
|
||||
} else {
|
||||
jsonGenerator.write(name, (BigDecimal) object);
|
||||
jsonGenerator.writeNumberField(name, ((BigInteger) object).longValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeBigInteger(String name, Number object) {
|
||||
private void writeDouble(String name, Number object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write((BigInteger) object);
|
||||
jsonGenerator.writeNumber((Double) object);
|
||||
} else {
|
||||
jsonGenerator.write(name, (BigInteger) object);
|
||||
jsonGenerator.writeNumberField(name, (Double) object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDouble(String name, Number object) {
|
||||
private void writeLong(String name, Number object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write((Double) object);
|
||||
jsonGenerator.writeNumber((Long) object);
|
||||
} else {
|
||||
jsonGenerator.write(name, (Double) object);
|
||||
jsonGenerator.writeNumberField(name, (Long) object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLong(String name, Number object) {
|
||||
private void writeInteger(String name, Number object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write((Long) object);
|
||||
jsonGenerator.writeNumber((Integer) object);
|
||||
} else {
|
||||
jsonGenerator.write(name, (Long) object);
|
||||
jsonGenerator.writeNumberField(name, (Integer) object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeInteger(String name, Number object) {
|
||||
if (name == null) {
|
||||
jsonGenerator.write((Integer) object);
|
||||
} else {
|
||||
jsonGenerator.write(name, (Integer) object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeNull(String name) {
|
||||
private void writeNull(String name) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.writeNull();
|
||||
} else {
|
||||
jsonGenerator.writeNull(name);
|
||||
jsonGenerator.writeNullField(name);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeString(String name, String object) {
|
||||
private void writeString(String name, String object) throws IOException {
|
||||
if (name == null) {
|
||||
jsonGenerator.write(object);
|
||||
jsonGenerator.writeString(object);
|
||||
} else {
|
||||
jsonGenerator.write(name, object);
|
||||
jsonGenerator.writeStringField(name, object);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCollection(String name, Collection<Object> collection) {
|
||||
if (name == null) {
|
||||
jsonGenerator.writeStartArray();
|
||||
} else {
|
||||
jsonGenerator.writeStartArray(name);
|
||||
}
|
||||
private void writeCollection(String name, Collection<Object> collection) throws IOException {
|
||||
if (name != null) {
|
||||
jsonGenerator.writeFieldName(name);
|
||||
}
|
||||
jsonGenerator.writeStartArray();
|
||||
for (Object object : collection) {
|
||||
writeJson(null, object);
|
||||
}
|
||||
jsonGenerator.writeEnd();
|
||||
jsonGenerator.writeEndArray();
|
||||
}
|
||||
|
||||
private void writeMap(String name, Map<Object, Object> map) {
|
||||
private void writeMap(String name, Map<Object, Object> map) throws IOException {
|
||||
|
||||
if (name == null) {
|
||||
jsonGenerator.writeStartObject();
|
||||
} else {
|
||||
jsonGenerator.writeStartObject(name);
|
||||
if (name != null) {
|
||||
jsonGenerator.writeFieldName(name);
|
||||
}
|
||||
jsonGenerator.writeStartObject();
|
||||
Set<Entry<Object, Object>> entrySet = map.entrySet();
|
||||
for (Entry<Object, Object> entry : entrySet) {
|
||||
writeJson(entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
jsonGenerator.writeEnd();
|
||||
jsonGenerator.writeEndObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.avaje.ebean.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
/**
|
||||
* Converts objects to and from JSON format.
|
||||
*
|
||||
@@ -15,34 +19,35 @@ public interface JsonContext {
|
||||
/**
|
||||
* Convert json string input into a Bean of a specific type.
|
||||
*/
|
||||
public <T> T toBean(Class<T> rootType, String json);
|
||||
public <T> T toBean(Class<T> rootType, String json) throws IOException;
|
||||
|
||||
/**
|
||||
* Convert json reader input into a Bean of a specific type.
|
||||
*/
|
||||
public <T> T toBean(Class<T> rootType, Reader json);
|
||||
public <T> T toBean(Class<T> rootType, Reader json) throws IOException;
|
||||
|
||||
/**
|
||||
* Convert json string input into a list of beans of a specific type.
|
||||
*/
|
||||
public <T> List<T> toList(Class<T> rootType, String json);
|
||||
public <T> List<T> toList(Class<T> rootType, String json) throws IOException;
|
||||
|
||||
/**
|
||||
* Convert json reader input into a list of beans of a specific type.
|
||||
* @throws IOException
|
||||
*/
|
||||
public <T> List<T> toList(Class<T> rootType, Reader json);
|
||||
public <T> List<T> toList(Class<T> rootType, Reader json) throws IOException;
|
||||
|
||||
/**
|
||||
* Use the genericType to determine if this should be converted into a List or
|
||||
* bean.
|
||||
*/
|
||||
public Object toObject(Type genericType, Reader json);
|
||||
public Object toObject(Type genericType, Reader json) throws IOException;
|
||||
|
||||
/**
|
||||
* Use the genericType to determine if this should be converted into a List or
|
||||
* bean.
|
||||
*/
|
||||
public Object toObject(Type genericType, String json);
|
||||
public Object toObject(Type genericType, String json) throws IOException;
|
||||
|
||||
/**
|
||||
* Write the bean or collection in JSON format to the writer with default
|
||||
@@ -53,7 +58,7 @@ public interface JsonContext {
|
||||
* @param writer
|
||||
* used to write the json output to
|
||||
*/
|
||||
public void toJsonWriter(Object o, Writer writer);
|
||||
public void toJsonWriter(Object o, Writer writer) throws IOException;
|
||||
|
||||
/**
|
||||
* With additional options to specify JsonValueAdapter and
|
||||
@@ -66,17 +71,17 @@ public interface JsonContext {
|
||||
* @param options
|
||||
* additional options to control the JSON output
|
||||
*/
|
||||
public void toJsonWriter(Object o, Writer writer, JsonWriteOptions options);
|
||||
public void toJsonWriter(Object o, Writer writer, JsonWriteOptions options) throws IOException;
|
||||
|
||||
/**
|
||||
* Convert a bean or collection to json string using default options.
|
||||
*/
|
||||
public String toJsonString(Object o);
|
||||
public String toJsonString(Object o) throws IOException;
|
||||
|
||||
/**
|
||||
* Convert a bean or collection to json string.
|
||||
*/
|
||||
public String toJsonString(Object o, JsonWriteOptions options);
|
||||
public String toJsonString(Object o, JsonWriteOptions options) throws IOException;
|
||||
|
||||
/**
|
||||
* Return true if the type is known as an Entity or Xml type or a List Set or
|
||||
@@ -84,4 +89,13 @@ public interface JsonContext {
|
||||
*/
|
||||
public boolean isSupportedType(Type genericType);
|
||||
|
||||
/**
|
||||
* Create and return a new JsonGenerator for the given writer.
|
||||
*/
|
||||
public JsonGenerator createGenerator(Writer writer) throws IOException;
|
||||
|
||||
/**
|
||||
* Create and return a new JsonParser for the given reader.
|
||||
*/
|
||||
public JsonParser createParser(Reader reader) throws IOException;
|
||||
}
|
||||
@@ -2081,11 +2081,18 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
return new CallStack(finalTrace);
|
||||
}
|
||||
|
||||
public JsonContext createJsonContext() {
|
||||
|
||||
@Override
|
||||
public JsonContext json() {
|
||||
// immutable thread safe so return shared instance
|
||||
return jsonContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonContext createJsonContext() {
|
||||
return json();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void collectQueryStats(ObjectGraphNode node, long loadedBeanCount, long timeMicros) {
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.avaje.ebeaninternal.server.transaction.TransactionManager;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionScopeManager;
|
||||
import com.avaje.ebeaninternal.server.type.DefaultTypeManager;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
|
||||
/**
|
||||
* Used to extend the ServerConfig with additional objects used to configure and
|
||||
@@ -88,10 +89,13 @@ public class InternalConfiguration {
|
||||
|
||||
private final XmlConfig xmlConfig;
|
||||
|
||||
private final JsonFactory jsonFactory;
|
||||
|
||||
public InternalConfiguration(XmlConfig xmlConfig, ClusterManager clusterManager,
|
||||
ServerCacheManager cacheManager, SpiBackgroundExecutor backgroundExecutor,
|
||||
ServerConfig serverConfig, BootupClasses bootupClasses, PstmtBatch pstmtBatch) {
|
||||
|
||||
this.jsonFactory = serverConfig.getJsonFactory();
|
||||
this.xmlConfig = xmlConfig;
|
||||
this.pstmtBatch = pstmtBatch;
|
||||
this.clusterManager = clusterManager;
|
||||
@@ -162,8 +166,7 @@ public class InternalConfiguration {
|
||||
|
||||
public JsonContext createJsonContext(SpiEbeanServer server) {
|
||||
|
||||
|
||||
return new DJsonContext(server);
|
||||
return new DJsonContext(server, jsonFactory);
|
||||
}
|
||||
|
||||
public XmlConfig getXmlConfig() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
@@ -59,9 +60,9 @@ public interface BeanCollectionHelp<T> {
|
||||
*/
|
||||
public void refresh(BeanCollection<?> bc, EntityBean parentBean);
|
||||
|
||||
/**
|
||||
* Write the collection out as json.
|
||||
*/
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude);
|
||||
/**
|
||||
* Write the collection out as json.
|
||||
*/
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,7 +14,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -67,6 +67,7 @@ import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
import com.avaje.ebeaninternal.util.SortByClause;
|
||||
import com.avaje.ebeaninternal.util.SortByClause.Property;
|
||||
import com.avaje.ebeaninternal.util.SortByClauseParser;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
/**
|
||||
* Describes Beans including their deployment information.
|
||||
@@ -2112,23 +2113,23 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return propertiesLocal;
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean) {
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean) throws IOException {
|
||||
jsonHelp.jsonWrite(writeJson, bean, null);
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean, String key) {
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean, String key) throws IOException {
|
||||
jsonHelp.jsonWrite(writeJson, bean, key);
|
||||
}
|
||||
|
||||
protected void jsonWriteProperties(WriteJson writeJson, EntityBean bean) {
|
||||
protected void jsonWriteProperties(WriteJson writeJson, EntityBean bean) throws IOException {
|
||||
jsonHelp.jsonWriteProperties(writeJson, bean);
|
||||
}
|
||||
|
||||
public T jsonRead(JsonParser parser, String path) {
|
||||
public T jsonRead(JsonParser parser, String path) throws IOException {
|
||||
return jsonHelp.jsonRead(parser, path);
|
||||
}
|
||||
|
||||
protected T jsonReadObject(JsonParser parser, String path) {
|
||||
protected T jsonReadObject(JsonParser parser, String path) throws IOException {
|
||||
return jsonHelp.jsonReadObject(parser, path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson.WriteBean;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
public class BeanDescriptorJsonHelp<T> {
|
||||
|
||||
@@ -19,31 +20,27 @@ public class BeanDescriptorJsonHelp<T> {
|
||||
this.inheritInfo = desc.inheritInfo;
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean, String key) {
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean, String key) throws IOException {
|
||||
|
||||
// if (writeJson.hasBean()) {
|
||||
writeJson.writeStartObject(key);
|
||||
|
||||
writeJson.writeStartObject(key);
|
||||
//WriteBeanState prevState = ctx.pushBeanState(bean);
|
||||
if (inheritInfo == null) {
|
||||
jsonWriteProperties(writeJson, bean);
|
||||
|
||||
if (inheritInfo == null) {
|
||||
jsonWriteProperties(writeJson, bean);
|
||||
|
||||
} else {
|
||||
InheritInfo localInheritInfo = inheritInfo.readType(bean.getClass());
|
||||
String discValue = localInheritInfo.getDiscriminatorStringValue();
|
||||
String discColumn = localInheritInfo.getDiscriminatorColumn();
|
||||
writeJson.gen().write(discColumn, discValue);
|
||||
} else {
|
||||
InheritInfo localInheritInfo = inheritInfo.readType(bean.getClass());
|
||||
String discValue = localInheritInfo.getDiscriminatorStringValue();
|
||||
String discColumn = localInheritInfo.getDiscriminatorColumn();
|
||||
writeJson.gen().writeStringField(discColumn, discValue);
|
||||
|
||||
BeanDescriptor<?> localDescriptor = localInheritInfo.getBeanDescriptor();
|
||||
localDescriptor.jsonWriteProperties(writeJson, bean);
|
||||
}
|
||||
BeanDescriptor<?> localDescriptor = localInheritInfo.getBeanDescriptor();
|
||||
localDescriptor.jsonWriteProperties(writeJson, bean);
|
||||
}
|
||||
|
||||
//ctx.pushPreviousState(prevState);
|
||||
writeJson.gen().writeEnd();
|
||||
writeJson.writeEndObject();
|
||||
}
|
||||
|
||||
protected void jsonWriteProperties(WriteJson writeJson, EntityBean bean) {
|
||||
protected void jsonWriteProperties(WriteJson writeJson, EntityBean bean) throws IOException {
|
||||
|
||||
|
||||
WriteBean writeBean = writeJson.createWriteBean(desc, bean);
|
||||
@@ -52,17 +49,14 @@ public class BeanDescriptorJsonHelp<T> {
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T jsonRead(JsonParser parser, String path) {
|
||||
public T jsonRead(JsonParser parser, String path) throws IOException {
|
||||
|
||||
if (!parser.hasNext()) {
|
||||
JsonToken token = parser.nextToken();
|
||||
if (JsonToken.VALUE_NULL == token || JsonToken.END_ARRAY == token) {
|
||||
return null;
|
||||
}
|
||||
Event event = parser.next();
|
||||
if (Event.VALUE_NULL == event || Event.END_ARRAY == event) {
|
||||
return null;
|
||||
}
|
||||
if (Event.START_OBJECT != event) {
|
||||
throw new RuntimeException("Unexpected token "+event+" - expecting start_object at: "+parser.getLocation());
|
||||
if (JsonToken.START_OBJECT != token) {
|
||||
throw new IOException("Unexpected token "+token+" - expecting start_object at: "+parser.getCurrentLocation());
|
||||
}
|
||||
|
||||
if (desc.inheritInfo == null) {
|
||||
@@ -72,12 +66,13 @@ public class BeanDescriptorJsonHelp<T> {
|
||||
// check for the discriminator value to determine the correct sub type
|
||||
String discColumn = inheritInfo.getRoot().getDiscriminatorColumn();
|
||||
|
||||
if (!parser.hasNext() || ((event = parser.next()) != Event.KEY_NAME)) {
|
||||
token = parser.nextToken();
|
||||
if (token != JsonToken.FIELD_NAME) {
|
||||
String msg = "Error reading inheritance discriminator - expected [" + discColumn + "] but no json key?";
|
||||
throw new TextException(msg);
|
||||
}
|
||||
|
||||
String propName = parser.getString();
|
||||
String propName = parser.getCurrentName();
|
||||
if (!propName.equalsIgnoreCase(discColumn)) {
|
||||
// just try to assume this is the correct bean type in the inheritance
|
||||
BeanProperty property = desc.getBeanProperty(propName);
|
||||
@@ -89,13 +84,8 @@ public class BeanDescriptorJsonHelp<T> {
|
||||
String msg = "Error reading inheritance discriminator, expected property ["+discColumn+"] but got [" + propName + "] ?";
|
||||
throw new TextException(msg);
|
||||
}
|
||||
|
||||
if (!parser.hasNext() || ((event = parser.next()) != Event.VALUE_STRING)) {
|
||||
String msg = "Error reading inheritance discriminator - expected value_string token but got [" + event + "] at ["+parser.getLocation()+"]?";
|
||||
throw new TextException(msg);
|
||||
}
|
||||
|
||||
String discValue = parser.getString();
|
||||
|
||||
String discValue = parser.nextTextValue();
|
||||
|
||||
// determine the sub type for this particular json object
|
||||
InheritInfo localInheritInfo = inheritInfo.readType(discValue);
|
||||
@@ -103,39 +93,35 @@ public class BeanDescriptorJsonHelp<T> {
|
||||
return (T) localDescriptor.jsonReadObject(parser, path);
|
||||
}
|
||||
|
||||
protected T jsonReadObject(JsonParser parser, String path) {
|
||||
protected T jsonReadObject(JsonParser parser, String path) throws IOException {
|
||||
|
||||
EntityBean bean = desc.createEntityBean();
|
||||
//ctx.pushBean(bean, path, this);
|
||||
|
||||
return jsonReadProperties(parser, bean);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T jsonReadProperties(JsonParser parser, EntityBean bean) {
|
||||
protected T jsonReadProperties(JsonParser parser, EntityBean bean) throws IOException {
|
||||
|
||||
do {
|
||||
|
||||
if (parser.hasNext()) {
|
||||
Event event = parser.next();
|
||||
if (Event.KEY_NAME == event) {
|
||||
String key = parser.getString();
|
||||
BeanProperty p = desc.getBeanProperty(key);
|
||||
if (p != null) {
|
||||
p.jsonRead(parser, bean);
|
||||
|
||||
} else {
|
||||
//Object rawValue = EJson.parse(parser);
|
||||
// unknown property key ...
|
||||
//ctx.readUnmappedJson(propName);
|
||||
}
|
||||
|
||||
} else if (Event.END_OBJECT == event) {
|
||||
break;
|
||||
|
||||
JsonToken event = parser.nextToken();
|
||||
if (JsonToken.FIELD_NAME == event) {
|
||||
String key = parser.getCurrentName();
|
||||
BeanProperty p = desc.getBeanProperty(key);
|
||||
if (p != null) {
|
||||
p.jsonRead(parser, bean);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unexpected token "+event+" - expecting key or end_object at: "+parser.getLocation());
|
||||
// Object rawValue = EJson.parse(parser);
|
||||
// unknown property key ...
|
||||
// ctx.readUnmappedJson(propName);
|
||||
}
|
||||
|
||||
} else if (JsonToken.END_OBJECT == event) {
|
||||
break;
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unexpected token " + event + " - expecting key or end_object at: " + parser.getCurrentLocation());
|
||||
}
|
||||
|
||||
} while (true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -128,7 +129,7 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) {
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) throws IOException {
|
||||
|
||||
List<?> list;
|
||||
if (collection instanceof BeanCollection<?>) {
|
||||
@@ -147,11 +148,11 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
list = (List<?>) collection;
|
||||
}
|
||||
|
||||
ctx.gen().writeStartArray(name);
|
||||
ctx.writeStartArray(name);
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean)list.get(j));
|
||||
}
|
||||
ctx.gen().writeEnd();
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -156,7 +157,7 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) {
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) throws IOException {
|
||||
|
||||
Map<?,?> map;
|
||||
if (collection instanceof BeanCollection<?>){
|
||||
@@ -175,14 +176,14 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
map = (Map<?,?>)collection;
|
||||
}
|
||||
|
||||
ctx.gen().writeStartArray(name);
|
||||
ctx.writeStartArray(name);
|
||||
Iterator<?> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<?, ?> entry = (Entry<?, ?>)it.next();
|
||||
//FIXME: json write map key ...
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean) entry.getValue());
|
||||
}
|
||||
ctx.gen().writeEnd();
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
@@ -34,6 +32,8 @@ import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Description of a property of a bean. Includes its deployment information such
|
||||
@@ -1186,32 +1186,30 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean) {
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean) throws IOException {
|
||||
if (!jsonSerialize) {
|
||||
return;
|
||||
}
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
writeJson.gen().writeNull(name);
|
||||
writeJson.writeNull(name);
|
||||
} else {
|
||||
scalarType.jsonWrite(writeJson.gen(), name, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonRead(JsonParser ctx, EntityBean bean) {
|
||||
public void jsonRead(JsonParser ctx, EntityBean bean) throws IOException {
|
||||
if (!jsonDeserialize) {
|
||||
return;
|
||||
}
|
||||
if (!ctx.hasNext()) {
|
||||
throw new RuntimeException(ctx.getLocation().toString());
|
||||
}
|
||||
Event event = ctx.next();
|
||||
if (Event.VALUE_NULL == event) {
|
||||
|
||||
JsonToken event = ctx.nextToken();
|
||||
if (JsonToken.VALUE_NULL == event) {
|
||||
setValue(bean, null);
|
||||
} else {
|
||||
// expect to read non-null json value
|
||||
Object objValue = scalarType.jsonRead(ctx, event);
|
||||
setValue(bean, objValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -30,6 +30,7 @@ import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
|
||||
import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
/**
|
||||
* Property mapped to a List Set or Map.
|
||||
@@ -877,7 +878,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return null != targetDescriptor.getId(otherBean);
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson ctx, EntityBean bean) {
|
||||
public void jsonWrite(WriteJson ctx, EntityBean bean) throws IOException {
|
||||
if(!this.jsonSerialize){
|
||||
return;
|
||||
}
|
||||
@@ -898,7 +899,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonRead(JsonParser parser, EntityBean parentBean) {
|
||||
public void jsonRead(JsonParser parser, EntityBean parentBean) throws IOException {
|
||||
jsonHelp.jsonRead(parser, parentBean);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -1,11 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.avaje.ebean.bean.BeanCollectionAdd;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
public class BeanPropertyAssocManyJsonHelp {
|
||||
|
||||
@@ -15,23 +16,24 @@ public class BeanPropertyAssocManyJsonHelp {
|
||||
this.many = many;
|
||||
}
|
||||
|
||||
public void jsonRead(JsonParser parser, EntityBean parentBean) {
|
||||
public void jsonRead(JsonParser parser, EntityBean parentBean) throws IOException {
|
||||
|
||||
if (!this.many.jsonDeserialize || !parser.hasNext()) {
|
||||
if (!this.many.jsonDeserialize) {
|
||||
return;
|
||||
}
|
||||
Event event = parser.next();
|
||||
if (Event.VALUE_NULL == event) {
|
||||
|
||||
JsonToken event = parser.nextToken();
|
||||
if (JsonToken.VALUE_NULL == event) {
|
||||
return;
|
||||
}
|
||||
if (Event.START_ARRAY != event) {
|
||||
throw new TextException("Unexpected token "+event+" - expecting start_array at: "+parser.getLocation());
|
||||
if (JsonToken.START_ARRAY != event) {
|
||||
throw new JsonParseException("Unexpected token " + event + " - expecting start_array ", parser.getCurrentLocation());
|
||||
}
|
||||
|
||||
|
||||
Object collection = many.createEmpty(false);
|
||||
BeanCollectionAdd add = many.getBeanCollectionAdd(collection, null);
|
||||
do {
|
||||
EntityBean detailBean = (EntityBean)many.targetDescriptor.jsonRead(parser, many.name);
|
||||
EntityBean detailBean = (EntityBean) many.targetDescriptor.jsonRead(parser, many.name);
|
||||
if (detailBean == null) {
|
||||
// read the entire array
|
||||
break;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
@@ -26,6 +26,7 @@ import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
|
||||
import com.avaje.ebeaninternal.server.query.SqlJoinType;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
/**
|
||||
* Property mapped to a joined bean.
|
||||
@@ -830,36 +831,40 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean) {
|
||||
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null){
|
||||
writeJson.gen().writeNull(name);
|
||||
|
||||
} else {
|
||||
if (writeJson.isParentBean(value)){
|
||||
// bi-directional and already rendered parent
|
||||
|
||||
} else {
|
||||
// Hmmm, not writing complex non-entity bean
|
||||
if (value instanceof EntityBean) {
|
||||
writeJson.beginAssocOne(name, bean);
|
||||
BeanDescriptor<?> refDesc = descriptor.getBeanDescriptor(value.getClass());
|
||||
refDesc.jsonWrite(writeJson, (EntityBean)value, name);
|
||||
writeJson.endAssocOne();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void jsonWrite(WriteJson writeJson, EntityBean bean) throws IOException {
|
||||
|
||||
if (!jsonSerialize) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonRead(JsonParser parser, EntityBean bean) {
|
||||
if (targetDescriptor != null) {
|
||||
T assocBean = targetDescriptor.jsonRead(parser, name);
|
||||
setValue(bean, assocBean);
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
writeJson.writeNull(name);
|
||||
|
||||
} else {
|
||||
if (writeJson.isParentBean(value)) {
|
||||
// bi-directional and already rendered parent
|
||||
|
||||
} else {
|
||||
// Hmmm, not writing complex non-entity bean
|
||||
if (value instanceof EntityBean) {
|
||||
writeJson.beginAssocOne(name, bean);
|
||||
BeanDescriptor<?> refDesc = descriptor.getBeanDescriptor(value.getClass());
|
||||
refDesc.jsonWrite(writeJson, (EntityBean) value, name);
|
||||
writeJson.endAssocOne();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonRead(JsonParser parser, EntityBean bean) throws IOException {
|
||||
if (jsonDeserialize && targetDescriptor != null) {
|
||||
T assocBean = targetDescriptor.jsonRead(parser, name);
|
||||
setValue(bean, assocBean);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReference(Object detailBean) {
|
||||
EntityBean eb = (EntityBean)detailBean;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebean.json.EJson;
|
||||
@@ -18,6 +17,7 @@ import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundProperty;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundPropertyElAdapter;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundType;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
/**
|
||||
* Property mapped to an Immutable Compound Value Object.
|
||||
@@ -180,19 +180,19 @@ public class BeanPropertyCompound extends BeanProperty {
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson ctx, EntityBean bean) {
|
||||
public void jsonWrite(WriteJson ctx, EntityBean bean) throws IOException {
|
||||
if (!jsonSerialize) {
|
||||
return;
|
||||
}
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
ctx.gen().writeNull(name);
|
||||
ctx.writeNull(name);
|
||||
} else {
|
||||
compoundType.jsonWrite(ctx, value, name);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonRead(JsonParser ctx, EntityBean bean) {
|
||||
public void jsonRead(JsonParser ctx, EntityBean bean) throws IOException {
|
||||
|
||||
if (!jsonDeserialize) {
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
@@ -129,7 +130,7 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) {
|
||||
public void jsonWrite(WriteJson ctx, String name, Object collection, boolean explicitInclude) throws IOException {
|
||||
|
||||
Set<?> set;
|
||||
if (collection instanceof BeanCollection<?>){
|
||||
@@ -148,11 +149,11 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
set = (Set<?>)collection;
|
||||
}
|
||||
|
||||
ctx.gen().writeStartArray(name);
|
||||
ctx.writeStartArray(name);
|
||||
Iterator<?> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean)it.next());
|
||||
}
|
||||
ctx.gen().writeEnd();
|
||||
ctx.writeEndArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
public class EJsonReader {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> parseObject(String json) {
|
||||
return (Map<String, Object>) parse(json);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Object> parseList(String json) {
|
||||
return (List<Object>) parse(json);
|
||||
}
|
||||
|
||||
public static Object parse(String json) {
|
||||
return parse(new StringReader(json));
|
||||
}
|
||||
|
||||
public static Object parse(Reader reader) {
|
||||
return parse(Json.createParser(reader));
|
||||
}
|
||||
|
||||
public static Object parse(JsonParser parser) {
|
||||
return new EJsonReader(parser).parseJson();
|
||||
}
|
||||
|
||||
private final JsonParser parser;
|
||||
|
||||
private final Stack stack = new Stack();
|
||||
|
||||
private Context currentContext;
|
||||
|
||||
|
||||
EJsonReader(JsonParser parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
private void startArray() {
|
||||
stack.push(currentContext);
|
||||
currentContext = new ArrayContext();
|
||||
}
|
||||
|
||||
private void startObject() {
|
||||
stack.push(currentContext);
|
||||
currentContext = new ObjectContext();
|
||||
}
|
||||
|
||||
private void endArray() {
|
||||
end();
|
||||
}
|
||||
|
||||
private void endObject() {
|
||||
end();
|
||||
}
|
||||
|
||||
private void end() {
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
currentContext = stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private void setValue(Object value) {
|
||||
currentContext.setValue(value);
|
||||
}
|
||||
|
||||
private void setValueNull() {
|
||||
currentContext.setValueNull();
|
||||
}
|
||||
|
||||
private Object parseJson() {
|
||||
|
||||
while (parser.hasNext()) {
|
||||
Event event = parser.next();
|
||||
switch (event) {
|
||||
|
||||
case START_ARRAY:
|
||||
startArray();
|
||||
break;
|
||||
|
||||
case START_OBJECT:
|
||||
startObject();
|
||||
break;
|
||||
|
||||
case KEY_NAME:
|
||||
currentContext.setKey(parser.getString());
|
||||
break;
|
||||
|
||||
case VALUE_STRING:
|
||||
setValue(parser.getString());
|
||||
break;
|
||||
|
||||
case VALUE_NUMBER:
|
||||
if (parser.isIntegralNumber()) {
|
||||
setValue(parser.getLong());
|
||||
} else {
|
||||
setValue(parser.getBigDecimal());
|
||||
}
|
||||
break;
|
||||
|
||||
case VALUE_TRUE:
|
||||
setValue(Boolean.TRUE);
|
||||
break;
|
||||
|
||||
case VALUE_FALSE:
|
||||
setValue(Boolean.FALSE);
|
||||
break;
|
||||
|
||||
case VALUE_NULL:
|
||||
setValueNull();
|
||||
break;
|
||||
|
||||
case END_OBJECT:
|
||||
endObject();
|
||||
break;
|
||||
|
||||
case END_ARRAY:
|
||||
endArray();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return currentContext.getValue();
|
||||
}
|
||||
|
||||
private static final class Stack {
|
||||
|
||||
private Context head;
|
||||
|
||||
private void push(Context context) {
|
||||
if (context != null) {
|
||||
context.next = head;
|
||||
head = context;
|
||||
}
|
||||
}
|
||||
|
||||
private Context pop() {
|
||||
if (head == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
Context temp = head;
|
||||
head = head.next;
|
||||
return temp;
|
||||
}
|
||||
|
||||
private boolean isEmpty() {
|
||||
return head == null;
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class Context {
|
||||
Context next;
|
||||
abstract Object getValue();
|
||||
abstract void setKey(String key);
|
||||
abstract void setValue(Object value);
|
||||
abstract void setValueNull();
|
||||
}
|
||||
|
||||
private static class ObjectContext extends Context {
|
||||
|
||||
private String key;
|
||||
|
||||
Map<String, Object> map = new LinkedHashMap<String,Object>();
|
||||
|
||||
Object getValue() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
void setValue(Object value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
void setValueNull() {
|
||||
map.put(key, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ArrayContext extends Context {
|
||||
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
|
||||
Object getValue() {
|
||||
return values;
|
||||
}
|
||||
|
||||
void setValue(Object value) {
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
void setValueNull() {
|
||||
}
|
||||
void setKey(String key) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
public class ReadJson {
|
||||
|
||||
JsonParser parser;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
@@ -13,11 +14,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.json.EJson;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
@@ -29,6 +25,11 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.util.ParamTypeHelper;
|
||||
import com.avaje.ebeaninternal.util.ParamTypeHelper.ManyType;
|
||||
import com.avaje.ebeaninternal.util.ParamTypeHelper.TypeInfo;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Default implementation of JsonContext.
|
||||
@@ -38,55 +39,59 @@ import com.avaje.ebeaninternal.util.ParamTypeHelper.TypeInfo;
|
||||
public class DJsonContext implements JsonContext {
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
private final JsonFactory jsonFactory;
|
||||
|
||||
public DJsonContext(SpiEbeanServer server) {
|
||||
public DJsonContext(SpiEbeanServer server, JsonFactory jsonFactory) {
|
||||
this.server = server;
|
||||
this.jsonFactory = (jsonFactory != null) ? jsonFactory : new JsonFactory();
|
||||
}
|
||||
|
||||
public boolean isSupportedType(Type genericType) {
|
||||
return server.isSupportedType(genericType);
|
||||
}
|
||||
|
||||
private JsonParser createReader(Reader jsonReader) {
|
||||
return Json.createParser(jsonReader);
|
||||
public JsonGenerator createGenerator(Writer writer) throws IOException {
|
||||
return jsonFactory.createGenerator(writer);
|
||||
}
|
||||
|
||||
public JsonParser createParser(Reader reader) throws IOException {
|
||||
return jsonFactory.createParser(reader);
|
||||
}
|
||||
|
||||
public <T> T toBean(Class<T> cls, String json) {
|
||||
public <T> T toBean(Class<T> cls, String json) throws IOException {
|
||||
return toBean(cls, new StringReader(json));
|
||||
}
|
||||
|
||||
public <T> T toBean(Class<T> cls, Reader jsonReader) {
|
||||
return toBean(cls, createReader(jsonReader));
|
||||
public <T> T toBean(Class<T> cls, Reader jsonReader) throws IOException {
|
||||
return toBean(cls, createParser(jsonReader));
|
||||
}
|
||||
|
||||
private <T> T toBean(Class<T> cls, JsonParser parser) {
|
||||
private <T> T toBean(Class<T> cls, JsonParser parser) throws IOException {
|
||||
|
||||
BeanDescriptor<T> d = getDecriptor(cls);
|
||||
return d.jsonRead(parser, null);
|
||||
}
|
||||
|
||||
public <T> List<T> toList(Class<T> cls, String json) {
|
||||
public <T> List<T> toList(Class<T> cls, String json) throws IOException {
|
||||
return toList(cls, new StringReader(json));
|
||||
}
|
||||
|
||||
|
||||
public <T> List<T> toList(Class<T> cls, Reader jsonReader) {
|
||||
return toList(cls, createReader(jsonReader));
|
||||
public <T> List<T> toList(Class<T> cls, Reader jsonReader) throws IOException {
|
||||
return toList(cls, createParser(jsonReader));
|
||||
}
|
||||
|
||||
private <T> List<T> toList(Class<T> cls, JsonParser src) {
|
||||
private <T> List<T> toList(Class<T> cls, JsonParser src) throws IOException {
|
||||
|
||||
try {
|
||||
BeanDescriptor<T> d = getDecriptor(cls);
|
||||
|
||||
List<T> list = new ArrayList<T>();
|
||||
|
||||
if (!src.hasNext()) {
|
||||
return list;
|
||||
}
|
||||
Event event = src.next();
|
||||
if (event != Event.START_ARRAY) {
|
||||
throw new TextException("Expecting start_array event but got [" + event + "] at [" + src.getLocation() + "]");
|
||||
JsonToken event = src.nextToken();
|
||||
if (event != JsonToken.START_ARRAY) {
|
||||
throw new JsonParseException("Expecting start_array event but got " + event ,src.getCurrentLocation());
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -105,7 +110,7 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
}
|
||||
|
||||
public Object toObject(Type genericType, String json) {
|
||||
public Object toObject(Type genericType, String json) throws IOException {
|
||||
|
||||
TypeInfo info = ParamTypeHelper.getTypeInfo(genericType);
|
||||
ManyType manyType = info.getManyType();
|
||||
@@ -121,7 +126,7 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
}
|
||||
|
||||
public Object toObject(Type genericType, Reader json) {
|
||||
public Object toObject(Type genericType, Reader json) throws IOException {
|
||||
|
||||
TypeInfo info = ParamTypeHelper.getTypeInfo(genericType);
|
||||
ManyType manyType = info.getManyType();
|
||||
@@ -137,40 +142,40 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
}
|
||||
|
||||
public void toJsonWriter(Object o, Writer writer) {
|
||||
public void toJsonWriter(Object o, Writer writer) throws IOException {
|
||||
toJsonWriter(o, writer, null);
|
||||
}
|
||||
|
||||
|
||||
public void toJsonWriter(Object o, Writer writer, JsonWriteOptions options) {
|
||||
JsonGenerator generator = Json.createGenerator(writer);
|
||||
public void toJsonWriter(Object o, Writer writer, JsonWriteOptions options) throws IOException {
|
||||
JsonGenerator generator = createGenerator(writer);
|
||||
toJsonInternal(o, generator, options);
|
||||
generator.close();
|
||||
}
|
||||
|
||||
public String toJsonString(Object o) {
|
||||
public String toJsonString(Object o) throws IOException {
|
||||
return toJsonString(o, null);
|
||||
}
|
||||
|
||||
public String toJsonString(Object o, JsonWriteOptions options) {
|
||||
public String toJsonString(Object o, JsonWriteOptions options) throws IOException {
|
||||
StringWriter writer = new StringWriter(500);
|
||||
JsonGenerator gen = Json.createGenerator(writer);
|
||||
JsonGenerator gen = createGenerator(writer);
|
||||
toJsonInternal(o, gen, options);
|
||||
gen.close();
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void toJsonInternal(Object o, JsonGenerator gen, JsonWriteOptions options) {
|
||||
private void toJsonInternal(Object o, JsonGenerator gen, JsonWriteOptions options) throws IOException {
|
||||
|
||||
if (o == null) {
|
||||
gen.writeNull();
|
||||
} else if (o instanceof Number) {
|
||||
gen.write(((Number) o).doubleValue());
|
||||
gen.writeNumber(((Number) o).doubleValue());
|
||||
} else if (o instanceof Boolean) {
|
||||
gen.write(((Boolean) o).booleanValue());
|
||||
gen.writeBoolean(((Boolean) o).booleanValue());
|
||||
} else if (o instanceof String) {
|
||||
gen.write((String) o);
|
||||
gen.writeString((String) o);
|
||||
|
||||
// } else if (o instanceof JsonElement) {
|
||||
|
||||
@@ -192,13 +197,12 @@ public class DJsonContext implements JsonContext {
|
||||
return new WriteJson(server, gen, pathProps);
|
||||
}
|
||||
|
||||
private <T> void toJsonFromCollection(Collection<T> c, String key, JsonGenerator gen, JsonWriteOptions options) {
|
||||
private <T> void toJsonFromCollection(Collection<T> c, String key, JsonGenerator gen, JsonWriteOptions options) throws IOException {
|
||||
|
||||
if (key == null) {
|
||||
gen.writeStartArray();
|
||||
} else {
|
||||
gen.writeStartArray(key);
|
||||
if (key != null) {
|
||||
gen.writeFieldName(key);
|
||||
}
|
||||
gen.writeStartArray();
|
||||
|
||||
WriteJson writeJson = createWriteJson(gen, options);
|
||||
|
||||
@@ -208,10 +212,10 @@ public class DJsonContext implements JsonContext {
|
||||
BeanDescriptor<?> d = getDecriptor(t.getClass());
|
||||
d.jsonWrite(writeJson, (EntityBean)t, null);
|
||||
}
|
||||
gen.writeEnd();
|
||||
gen.writeEndArray();
|
||||
}
|
||||
|
||||
private void toJsonFromMap(Map<Object, Object> map, JsonGenerator gen, JsonWriteOptions options) {
|
||||
private void toJsonFromMap(Map<Object, Object> map, JsonGenerator gen, JsonWriteOptions options) throws IOException {
|
||||
|
||||
Set<Entry<Object, Object>> entrySet = map.entrySet();
|
||||
Iterator<Entry<Object, Object>> it = entrySet.iterator();
|
||||
@@ -224,7 +228,7 @@ public class DJsonContext implements JsonContext {
|
||||
String key = entry.getKey().toString();
|
||||
Object value = entry.getValue();
|
||||
if (value == null) {
|
||||
gen.writeNull(key);
|
||||
gen.writeNullField(key);
|
||||
} else {
|
||||
if (value instanceof Collection<?>) {
|
||||
toJsonFromCollection((Collection<?>) value, key, gen, options);
|
||||
@@ -238,7 +242,7 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
}
|
||||
}
|
||||
gen.writeEnd();
|
||||
gen.writeEndObject();
|
||||
}
|
||||
|
||||
private <T> BeanDescriptor<T> getDecriptor(Class<T> cls) {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
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.util.ArrayStack;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
public class WriteJson {
|
||||
|
||||
@@ -122,8 +122,8 @@ public class WriteJson {
|
||||
}
|
||||
}
|
||||
|
||||
public void write(WriteJson writeJson) {
|
||||
//EntityBean bean = writeJson.getBean();
|
||||
public void write(WriteJson writeJson) throws IOException {
|
||||
|
||||
BeanProperty beanProp = desc.getIdProperty();
|
||||
if (beanProp != null) {
|
||||
if (isIncludeProperty(beanProp)) {
|
||||
@@ -159,7 +159,7 @@ public class WriteJson {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void toJson(String name, Collection<?> c) {
|
||||
public void toJson(String name, Collection<?> c) throws IOException {
|
||||
|
||||
beginAssocMany(name);
|
||||
|
||||
@@ -181,22 +181,40 @@ public class WriteJson {
|
||||
return d;
|
||||
}
|
||||
|
||||
public void beginAssocMany(String key) {
|
||||
public void beginAssocMany(String key) throws IOException {
|
||||
pathStack.pushPathKey(key);
|
||||
generator.writeStartArray(key);
|
||||
generator.writeFieldName(key);
|
||||
generator.writeStartArray();
|
||||
}
|
||||
|
||||
public void endAssocMany() {
|
||||
public void endAssocMany() throws IOException {
|
||||
pathStack.pop();
|
||||
generator.writeEnd();
|
||||
generator.writeEndArray();
|
||||
}
|
||||
|
||||
public void writeStartObject(String key) {
|
||||
if (key == null) {
|
||||
generator.writeStartObject();
|
||||
} else {
|
||||
generator.writeStartObject(key);
|
||||
public void writeStartArray(String key) throws IOException {
|
||||
if (key != null) {
|
||||
generator.writeFieldName(key);
|
||||
}
|
||||
generator.writeStartArray();
|
||||
}
|
||||
|
||||
public void writeStartObject(String key) throws IOException {
|
||||
if (key != null) {
|
||||
generator.writeFieldName(key);
|
||||
}
|
||||
generator.writeStartObject();
|
||||
}
|
||||
|
||||
public void writeNull(String name) throws IOException {
|
||||
generator.writeNullField(name);
|
||||
}
|
||||
|
||||
public void writeEndObject() throws IOException {
|
||||
generator.writeEndObject();
|
||||
}
|
||||
|
||||
public void writeEndArray() throws IOException {
|
||||
generator.writeEndArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -195,7 +196,7 @@ public final class CtCompoundType<V> implements ScalarDataReader<V> {
|
||||
}
|
||||
|
||||
|
||||
public void jsonWrite(WriteJson ctx, Object valueObject, String propertyName) {
|
||||
public void jsonWrite(WriteJson ctx, Object valueObject, String propertyName) throws IOException {
|
||||
|
||||
ctx.beginAssocOne(propertyName, valueObject);
|
||||
jsonWriteProps(ctx, valueObject, propertyName);
|
||||
@@ -203,13 +204,12 @@ public final class CtCompoundType<V> implements ScalarDataReader<V> {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void jsonWriteProps(WriteJson ctx, Object valueObject, String propertyName) {
|
||||
private void jsonWriteProps(WriteJson ctx, Object valueObject, String propertyName) throws IOException {
|
||||
|
||||
if (propertyName != null) {
|
||||
ctx.gen().writeStartObject(propertyName);
|
||||
} else {
|
||||
ctx.gen().writeStartObject();
|
||||
}
|
||||
ctx.gen().writeFieldName(propertyName);
|
||||
}
|
||||
ctx.gen().writeStartObject();
|
||||
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
String propName = properties[i].getName();
|
||||
@@ -223,7 +223,7 @@ public final class CtCompoundType<V> implements ScalarDataReader<V> {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.gen().writeEnd();
|
||||
ctx.gen().writeEndObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.StringFormatter;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Describes a scalar type.
|
||||
@@ -189,8 +188,8 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
|
||||
public void writeData(DataOutput dataOutput, Object v) throws IOException;
|
||||
|
||||
public Object jsonRead(JsonParser ctx, Event event);
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException;
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Base class for Date types.
|
||||
@@ -63,18 +63,18 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
if (ctx.isIntegralNumber()) {
|
||||
return parseDateTime(ctx.getLong());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
if (JsonToken.VALUE_NUMBER_INT == event) {
|
||||
return parseDateTime(ctx.getLongValue());
|
||||
} else {
|
||||
String string = ctx.getString();
|
||||
throw new RuntimeException("convert "+string);
|
||||
String string = ctx.getText();
|
||||
throw new RuntimeException("convert " + string);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
long millis = convertToMillis(value);
|
||||
ctx.write(name, millis);
|
||||
ctx.writeNumberField(name, millis);
|
||||
}
|
||||
|
||||
public abstract long convertToMillis(Object value);
|
||||
|
||||
@@ -7,9 +7,9 @@ import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Base type for DateTime types.
|
||||
@@ -45,21 +45,23 @@ public abstract class ScalarTypeBaseDateTime<T> extends ScalarTypeBase<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
if (ctx.isIntegralNumber()) {
|
||||
long millis = ctx.getLong();
|
||||
return parseDateTime(millis);
|
||||
} else {
|
||||
String string = ctx.getString();
|
||||
throw new RuntimeException("convert "+string);
|
||||
}
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
|
||||
if (JsonToken.VALUE_NUMBER_INT == event) {
|
||||
long millis = ctx.getLongValue();
|
||||
return parseDateTime(millis);
|
||||
|
||||
} else {
|
||||
String string = ctx.getText();
|
||||
throw new RuntimeException("convert " + string);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
long millis = convertToMillis(value);
|
||||
ctx.write(name, millis);
|
||||
ctx.writeNumberField(name, millis);
|
||||
}
|
||||
|
||||
public String formatValue(T t) {
|
||||
|
||||
@@ -6,11 +6,10 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Base ScalarType for types which converts to and from a VARCHAR database
|
||||
@@ -106,11 +105,11 @@ public abstract class ScalarTypeBaseVarchar<T> extends ScalarTypeBase<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return parse(ctx.getString());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return parse(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, format(value));
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, format(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,13 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for BigDecimal.
|
||||
@@ -81,12 +79,12 @@ public class ScalarTypeBigDecimal extends ScalarTypeBase<BigDecimal> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getBigDecimal();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getDecimalValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (BigDecimal)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, (BigDecimal)value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,16 +3,14 @@ package com.avaje.ebeaninternal.server.type;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Boolean and boolean.
|
||||
@@ -293,12 +291,12 @@ public class ScalarTypeBoolean {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return Event.VALUE_TRUE == event ? Boolean.TRUE : Boolean.FALSE;
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) {
|
||||
return JsonToken.VALUE_TRUE == event ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (Boolean)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeBooleanField(name, (Boolean)value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,11 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Byte.
|
||||
@@ -48,7 +47,7 @@ public class ScalarTypeByte extends ScalarTypeBase<Byte> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) {
|
||||
throw new TextException("Not supported");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,10 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Base type for binary types.
|
||||
@@ -51,7 +50,7 @@ public abstract class ScalarTypeBytesBase extends ScalarTypeBase<byte[]> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) {
|
||||
throw new TextException("Not supported");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,10 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Encrypted ScalarType that wraps a byte[] types.
|
||||
@@ -74,7 +73,7 @@ public class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) {
|
||||
throw new TextException("Not supported");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for char.
|
||||
@@ -61,11 +61,10 @@ public class ScalarTypeChar extends ScalarTypeBaseVarchar<Character> {
|
||||
public Character parse(String value) {
|
||||
return value.charAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getValueAsString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for char[].
|
||||
@@ -64,11 +64,11 @@ public class ScalarTypeCharArray extends ScalarTypeBaseVarchar<char[]>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getString().toCharArray();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getValueAsString().toCharArray();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, String.valueOf(value));
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
/**
|
||||
* ScalarType for Class that persists it to VARCHAR column.
|
||||
*
|
||||
@@ -44,8 +47,8 @@ public class ScalarTypeClass extends ScalarTypeBaseVarchar<Class> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, formatValue((Class<?>)value));
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, formatValue((Class<?>)value));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Currency;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
|
||||
@@ -39,11 +40,11 @@ public class ScalarTypeCurrency extends ScalarTypeBaseVarchar<Currency> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return parse(ctx.getString());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return parse(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, formatValue((Currency)value));
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, formatValue((Currency)value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,11 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.Currency;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Double and double.
|
||||
@@ -89,11 +87,11 @@ public class ScalarTypeDouble extends ScalarTypeBase<Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getBigDecimal().doubleValue();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getDoubleValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (Double)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, (Double)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T> {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return wrapped.jsonRead(ctx, event);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T> {
|
||||
wrapped.accumulateScalarTypes(propName, list);
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
wrapped.jsonWrite(ctx, name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
|
||||
/**
|
||||
@@ -230,14 +229,14 @@ public class ScalarTypeEnumStandard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
|
||||
String val = ctx.getString();
|
||||
String val = ctx.getValueAsString();
|
||||
return parse(val);
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, formatValue(value));
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, formatValue(value));
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
@@ -6,11 +6,10 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Float and float.
|
||||
@@ -87,11 +86,11 @@ public class ScalarTypeFloat extends ScalarTypeBase<Float> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getBigDecimal().floatValue();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getFloatValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (Float)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, (Float)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Integer and int.
|
||||
@@ -68,11 +67,11 @@ public class ScalarTypeInteger extends ScalarTypeBase<Integer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return Integer.valueOf(ctx.getInt());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getIntValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (Integer) value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, (Integer) value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.sql.Date;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.joda.time.DateMidnight;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
|
||||
@@ -7,14 +7,13 @@ import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalTime;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Joda LocalTime. This maps to a JDBC Time.
|
||||
@@ -67,17 +66,17 @@ public class ScalarTypeJodaLocalTime extends ScalarTypeBase<LocalTime> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(value.toString());
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
if (ctx.isIntegralNumber()) {
|
||||
long millis = ctx.getLong();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
if (JsonToken.VALUE_NUMBER_INT == event) {
|
||||
long millis = ctx.getLongValue();
|
||||
return parseDateTime(millis);
|
||||
} else {
|
||||
String string = ctx.getString();
|
||||
String string = ctx.getValueAsString();
|
||||
throw new RuntimeException("convert "+string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,10 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Long and long.
|
||||
@@ -79,11 +78,11 @@ public class ScalarTypeLong extends ScalarTypeBase<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getLong();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getLongValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (Long)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, (Long)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ import java.math.BigInteger;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for java.math.BigInteger.
|
||||
@@ -85,12 +84,12 @@ public class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getBigDecimal().toBigInteger();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getDecimalValue().toBigInteger();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (BigInteger)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, ((BigInteger)value).longValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,11 +6,10 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.PostgresPlatform;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* Postgres Hstore type which maps Map<String,String> to a single 'HStore column' in the DB.
|
||||
@@ -74,7 +73,7 @@ public class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for Short and short.
|
||||
@@ -80,11 +79,11 @@ public class ScalarTypeShort extends ScalarTypeBase<Short> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return (short)ctx.getInt();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getShortValue();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (Short)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeNumberField(name, (Short)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,10 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for String.
|
||||
@@ -78,11 +77,11 @@ public class ScalarTypeString extends ScalarTypeBase<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return ctx.getString();
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getValueAsString();
|
||||
}
|
||||
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, (String)value);
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, (String)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for java.sql.Time.
|
||||
@@ -81,13 +80,13 @@ public class ScalarTypeTime extends ScalarTypeBase<Time> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return parse(ctx.getString());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return parse(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, value.toString());
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for java.net.URL which converts to and from a VARCHAR database column.
|
||||
@@ -45,8 +45,8 @@ public class ScalarTypeURL extends ScalarTypeBaseVarchar<URL> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return parse(ctx.getString());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return parse(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
public class ScalarTypeUUIDBinary extends ScalarTypeBase<UUID> {
|
||||
|
||||
@@ -143,13 +143,13 @@ public class ScalarTypeUUIDBinary extends ScalarTypeBase<UUID> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return UUID.fromString(ctx.getString());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return UUID.fromString(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) {
|
||||
ctx.write(name, value.toString());
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
|
||||
ctx.writeStringField(name, value.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.UUID which converts to and from a VARCHAR database column.
|
||||
@@ -48,8 +48,8 @@ public class ScalarTypeUUIDVarchar extends ScalarTypeBaseVarchar<UUID> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
return UUID.fromString(ctx.getString());
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return UUID.fromString(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* A ScalarType that uses a ScalarTypeConverter to convert to and from another
|
||||
@@ -169,13 +168,13 @@ public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object jsonRead(JsonParser ctx, Event event) {
|
||||
public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
Object object = scalarType.jsonRead(ctx, event);
|
||||
return converter.wrapValue((S)object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object beanValue) {
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Object beanValue) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
S unwrapValue = converter.unwrapValue((B)beanValue);
|
||||
scalarType.jsonWrite(ctx, name, unwrapValue);
|
||||
|
||||
Reference in New Issue
Block a user