mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1145 - Refactor @ChangeLog based on JSON documents for 'new values' and 'old values'
This commit is contained in:
1 parent
daf3d97266
commit
368d22baa6
35 files changed
+743
-503
No files matched your search
@@ -1,26 +1,26 @@
|
||||
package io.ebeaninternal.server.text.json;
|
||||
|
||||
import io.ebean.FetchPath;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.plugin.BeanType;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebean.text.json.JsonContext;
|
||||
import io.ebean.text.json.JsonIOException;
|
||||
import io.ebean.text.json.JsonReadOptions;
|
||||
import io.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import io.ebean.text.json.JsonWriteOptions;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.type.TypeManager;
|
||||
import io.ebeaninternal.util.ParamTypeHelper;
|
||||
import io.ebeaninternal.util.ParamTypeHelper.ManyType;
|
||||
import io.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;
|
||||
import io.ebean.FetchPath;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.plugin.BeanType;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebean.text.json.JsonIOException;
|
||||
import io.ebean.text.json.JsonReadOptions;
|
||||
import io.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import io.ebean.text.json.JsonWriteOptions;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiJsonContext;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.type.TypeManager;
|
||||
import io.ebeaninternal.util.ParamTypeHelper;
|
||||
import io.ebeaninternal.util.ParamTypeHelper.ManyType;
|
||||
import io.ebeaninternal.util.ParamTypeHelper.TypeInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@@ -39,7 +39,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Default implementation of JsonContext.
|
||||
*/
|
||||
public class DJsonContext implements JsonContext {
|
||||
public class DJsonContext implements SpiJsonContext {
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
@@ -179,7 +179,7 @@ public class DJsonContext implements JsonContext {
|
||||
if (currentToken != JsonToken.START_ARRAY) {
|
||||
JsonToken event = src.nextToken();
|
||||
if (event != JsonToken.START_ARRAY) {
|
||||
throw new JsonParseException("Expecting start_array event but got " + event, src.getCurrentLocation());
|
||||
throw new JsonParseException(src, "Expecting start_array event but got " + event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,9 +336,23 @@ public class DJsonContext implements JsonContext {
|
||||
BeanDescriptor<?> d = getDescriptor(value.getClass());
|
||||
WriteJson writeJson = createWriteJson(gen, options);
|
||||
d.jsonWrite(writeJson, (EntityBean) value, null);
|
||||
|
||||
} else {
|
||||
jsonScalar.write(gen, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpiJsonWriter createJsonWriter(Writer writer) {
|
||||
JsonGenerator generator = createGenerator(writer);
|
||||
return createJsonWriter(generator, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpiJsonWriter createJsonWriter(JsonGenerator gen, JsonWriteOptions options) {
|
||||
return createWriteJson(gen, options);
|
||||
}
|
||||
|
||||
private WriteJson createWriteJson(JsonGenerator gen, JsonWriteOptions options) {
|
||||
FetchPath pathProps = (options == null) ? null : options.getPathProperties();
|
||||
Map<String, JsonWriteBeanVisitor<?>> visitors = (options == null) ? null : options.getVisitorMap();
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.ebeaninternal.server.text.json;
|
||||
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.text.json.JsonWriter;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Internal API extensions for JSON writing of Bean properties.
|
||||
*/
|
||||
public interface SpiJsonWriter extends JsonWriter {
|
||||
|
||||
/**
|
||||
* Return true if the value is a parent bean.
|
||||
*/
|
||||
boolean isParentBean(Object value);
|
||||
|
||||
/**
|
||||
* Start an assoc one path.
|
||||
*/
|
||||
void beginAssocOne(String name, EntityBean bean);
|
||||
|
||||
/**
|
||||
* End an assoc one path.
|
||||
*/
|
||||
void endAssocOne();
|
||||
|
||||
/**
|
||||
* Return true if the many property should be included.
|
||||
*/
|
||||
Boolean includeMany(String name);
|
||||
|
||||
/**
|
||||
* Push the parent bean of a ToMany.
|
||||
*/
|
||||
void pushParentBeanMany(EntityBean bean);
|
||||
|
||||
/**
|
||||
* Pop the parent of a ToMany.
|
||||
*/
|
||||
void popParentBeanMany();
|
||||
|
||||
/**
|
||||
* Write the collection.
|
||||
*/
|
||||
void toJson(String name, Collection<?> collection);
|
||||
|
||||
/**
|
||||
* Start a Many.
|
||||
*/
|
||||
void beginAssocMany(String name);
|
||||
|
||||
/**
|
||||
* End a Many.
|
||||
*/
|
||||
void endAssocMany();
|
||||
|
||||
/**
|
||||
* Write value using underlying Jaskson object mapper if available.
|
||||
*/
|
||||
void writeValueUsingObjectMapper(String name, Object value);
|
||||
|
||||
/**
|
||||
* Write the bean properties.
|
||||
*/
|
||||
<T> void writeBean(BeanDescriptor<T> desc, EntityBean bean);
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
package io.ebeaninternal.server.text.json;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.ebean.FetchPath;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebean.text.json.JsonIOException;
|
||||
import io.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import io.ebean.text.json.JsonWriter;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.util.ArrayStack;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -21,7 +20,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class WriteJson implements JsonWriter {
|
||||
public class WriteJson implements SpiJsonWriter {
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
@@ -347,7 +346,7 @@ public class WriteJson implements JsonWriter {
|
||||
return !parentBeans.isEmpty() && parentBeans.contains(bean);
|
||||
}
|
||||
|
||||
public void pushParentBeanMany(Object parentBean) {
|
||||
public void pushParentBeanMany(EntityBean parentBean) {
|
||||
parentBeans.push(parentBean);
|
||||
}
|
||||
|
||||
@@ -355,7 +354,7 @@ public class WriteJson implements JsonWriter {
|
||||
parentBeans.pop();
|
||||
}
|
||||
|
||||
public void beginAssocOne(String key, Object bean) {
|
||||
public void beginAssocOne(String key, EntityBean bean) {
|
||||
parentBeans.push(bean);
|
||||
pathStack.pushPathKey(key);
|
||||
}
|
||||
@@ -384,7 +383,12 @@ public class WriteJson implements JsonWriter {
|
||||
}
|
||||
}
|
||||
|
||||
public WriteBean createWriteBean(BeanDescriptor<?> desc, EntityBean bean) {
|
||||
@Override
|
||||
public <T> void writeBean(BeanDescriptor<T> desc, EntityBean bean) {
|
||||
createWriteBean(desc, bean).write(this);
|
||||
}
|
||||
|
||||
private <T> WriteBean createWriteBean(BeanDescriptor<T> desc, EntityBean bean) {
|
||||
|
||||
String path = pathStack.peekWithNull();
|
||||
JsonWriteBeanVisitor<?> visitor = (visitors == null) ? null : visitors.get(path);
|
||||
@@ -436,7 +440,7 @@ public class WriteJson implements JsonWriter {
|
||||
final Set<String> currentIncludeProps;
|
||||
final BeanDescriptor<?> desc;
|
||||
final EntityBean currentBean;
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
final JsonWriteBeanVisitor visitor;
|
||||
|
||||
|
||||
Reference in new issue
Block a user