mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
#575 - Refactor PathProperties, extract FetchPath interface, rename get(path) -> getProperties(path)
This commit is contained in:
1 parent
eda7fe24c1
commit
6561c118ec
18 files changed
+413
-244
No files matched your search
@@ -1,21 +1,40 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.FetchPath;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.json.*;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebean.text.json.EJson;
|
||||
import com.avaje.ebean.text.json.JsonContext;
|
||||
import com.avaje.ebean.text.json.JsonIOException;
|
||||
import com.avaje.ebean.text.json.JsonReadOptions;
|
||||
import com.avaje.ebean.text.json.JsonScalar;
|
||||
import com.avaje.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import com.avaje.ebean.text.json.JsonWriteOptions;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
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.*;
|
||||
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 java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Default implementation of JsonContext.
|
||||
@@ -181,9 +200,9 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(Object value, JsonGenerator generator, PathProperties pathProperties) throws JsonIOException {
|
||||
public void toJson(Object value, JsonGenerator generator, FetchPath fetchPath) throws JsonIOException {
|
||||
// generator passed in so don't close it
|
||||
toJsonNoClose(value, generator, JsonWriteOptions.pathProperties(pathProperties));
|
||||
toJsonNoClose(value, generator, JsonWriteOptions.pathProperties(fetchPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,14 +218,14 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(Object value, PathProperties pathProperties) throws JsonIOException {
|
||||
return toJson(value, JsonWriteOptions.pathProperties(pathProperties));
|
||||
public String toJson(Object value, FetchPath fetchPath) throws JsonIOException {
|
||||
return toJson(value, JsonWriteOptions.pathProperties(fetchPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(Object o, Writer writer, PathProperties pathProperties) throws JsonIOException {
|
||||
public void toJson(Object o, Writer writer, FetchPath fetchPath) throws JsonIOException {
|
||||
// close generator
|
||||
toJsonWithClose(o, createGenerator(writer), JsonWriteOptions.pathProperties(pathProperties));
|
||||
toJsonWithClose(o, createGenerator(writer), JsonWriteOptions.pathProperties(fetchPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,7 +307,7 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
|
||||
private WriteJson createWriteJson(JsonGenerator gen, JsonWriteOptions options) {
|
||||
PathProperties pathProps = (options == null) ? null : options.getPathProperties();
|
||||
FetchPath pathProps = (options == null) ? null : options.getPathProperties();
|
||||
Map<String, JsonWriteBeanVisitor<?>> visitors = (options == null) ? null : options.getVisitorMap();
|
||||
return new WriteJson(server, gen, pathProps, visitors, determineObjectMapper(options), determineInclude(options));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.FetchPath;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebean.text.json.JsonIOException;
|
||||
import com.avaje.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import com.avaje.ebean.text.json.JsonWriter;
|
||||
@@ -26,7 +26,7 @@ public class WriteJson implements JsonWriter {
|
||||
|
||||
private final JsonGenerator generator;
|
||||
|
||||
private final PathProperties pathProperties;
|
||||
private final FetchPath fetchPath;
|
||||
|
||||
private final Map<String, JsonWriteBeanVisitor<?>> visitors;
|
||||
|
||||
@@ -41,12 +41,12 @@ public class WriteJson implements JsonWriter {
|
||||
/**
|
||||
* Construct for full bean use (normal).
|
||||
*/
|
||||
public WriteJson(SpiEbeanServer server, JsonGenerator generator, PathProperties pathProperties,
|
||||
public WriteJson(SpiEbeanServer server, JsonGenerator generator, FetchPath fetchPath,
|
||||
Map<String, JsonWriteBeanVisitor<?>> visitors, Object objectMapper, JsonConfig.Include include) {
|
||||
|
||||
this.server = server;
|
||||
this.generator = generator;
|
||||
this.pathProperties = pathProperties;
|
||||
this.fetchPath = fetchPath;
|
||||
this.visitors = visitors;
|
||||
this.objectMapper = objectMapper;
|
||||
this.include = include;
|
||||
@@ -62,7 +62,7 @@ public class WriteJson implements JsonWriter {
|
||||
this.include = include;
|
||||
this.visitors = null;
|
||||
this.server = null;
|
||||
this.pathProperties = null;
|
||||
this.fetchPath = null;
|
||||
this.objectMapper = null;
|
||||
this.parentBeans = null;
|
||||
this.pathStack = null;
|
||||
@@ -376,12 +376,12 @@ public class WriteJson implements JsonWriter {
|
||||
|
||||
String path = pathStack.peekWithNull();
|
||||
JsonWriteBeanVisitor visitor = (visitors == null) ? null : visitors.get(path);
|
||||
if (pathProperties == null) {
|
||||
if (fetchPath == null) {
|
||||
return new WriteBean(desc, bean, visitor);
|
||||
}
|
||||
|
||||
boolean explicitAllProps = false;
|
||||
Set<String> currentIncludeProps = pathProperties.get(path);
|
||||
Set<String> currentIncludeProps = fetchPath.getProperties(path);
|
||||
if (currentIncludeProps != null) {
|
||||
explicitAllProps = currentIncludeProps.contains("*");
|
||||
if (explicitAllProps || currentIncludeProps.isEmpty()) {
|
||||
@@ -503,9 +503,9 @@ public class WriteJson implements JsonWriter {
|
||||
}
|
||||
|
||||
public Boolean includeMany(String key) {
|
||||
if (pathProperties != null) {
|
||||
if (fetchPath != null) {
|
||||
String fullPath = pathStack.peekFullPath(key);
|
||||
return pathProperties.hasPath(fullPath);
|
||||
return fetchPath.hasPath(fullPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user