mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
WIP on JSON refactor
This commit is contained in:
1 parent
7966d74eb3
commit
0ceda6406e
52 files changed
+1583
-174
No files matched your search
@@ -10,6 +10,9 @@ import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.json.stream.JsonParser.Event;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
@@ -18,7 +21,6 @@ import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.text.StringFormatter;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
|
||||
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
|
||||
@@ -30,7 +32,6 @@ import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
|
||||
import com.avaje.ebeaninternal.server.query.SqlJoinType;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectGetter;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
|
||||
import com.avaje.ebeaninternal.server.text.json.ReadJsonContext;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
@@ -1173,6 +1174,22 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void jsonWrite(JsonGenerator ctx, EntityBean bean) {
|
||||
if(!jsonSerialize){
|
||||
return;
|
||||
}
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
ctx.writeNull(name);
|
||||
} else {
|
||||
scalarType.jsonWrite(ctx, name, value);
|
||||
//ctx.appendNameValue(name, scalarType, value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
|
||||
if(!jsonSerialize){
|
||||
@@ -1186,22 +1203,39 @@ public class BeanProperty implements ElPropertyValue {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonRead(ReadJsonContext ctx, EntityBean bean) {
|
||||
if(!jsonDeserialize){
|
||||
return;
|
||||
}
|
||||
String jsonValue;
|
||||
try {
|
||||
jsonValue = ctx.readScalarValue();
|
||||
} catch (TextException e){
|
||||
throw new TextException("Error reading property "+getFullBeanName(), e);
|
||||
}
|
||||
Object objValue;
|
||||
if (jsonValue == null) {
|
||||
objValue = null;
|
||||
} else {
|
||||
objValue = scalarType.jsonFromString(jsonValue, ctx.getValueAdapter());
|
||||
}
|
||||
setValue(bean, objValue);
|
||||
// public void jsonRead(ReadJsonContext ctx, EntityBean bean) {
|
||||
// if(!jsonDeserialize){
|
||||
// return;
|
||||
// }
|
||||
// String jsonValue;
|
||||
// try {
|
||||
// jsonValue = ctx.readScalarValue();
|
||||
// } catch (TextException e){
|
||||
// throw new TextException("Error reading property "+getFullBeanName(), e);
|
||||
// }
|
||||
// Object objValue;
|
||||
// if (jsonValue == null) {
|
||||
// objValue = null;
|
||||
// } else {
|
||||
// objValue = scalarType.jsonFromString(jsonValue, ctx.getValueAdapter());
|
||||
// }
|
||||
// setValue(bean, objValue);
|
||||
// }
|
||||
|
||||
public void jsonRead(JsonParser ctx, EntityBean bean) {
|
||||
if (!jsonDeserialize) {
|
||||
return;
|
||||
}
|
||||
if (!ctx.hasNext()) {
|
||||
throw new RuntimeException(ctx.getLocation().toString());
|
||||
}
|
||||
Event event = ctx.next();
|
||||
if (Event.VALUE_NULL == event) {
|
||||
setValue(bean, null);
|
||||
} else {
|
||||
Object objValue = scalarType.jsonRead(ctx, event);
|
||||
setValue(bean, objValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user