Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ebean-core-json/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.ebean</groupId>
<artifactId>ebean-parent</artifactId>
<version>16.0.0-RC3</version>
</parent>
<artifactId>ebean-core-json</artifactId>
<scm>
<developerConnection>scm:git:[email protected]:ebean-orm/ebean.git</developerConnection>
<tag>HEAD</tag>
</scm>

<dependencies>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>16.0.0-RC3</version>
</dependency>

<!-- Jackson core used internally by Ebean -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<optional>true</optional>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Utility that converts between JSON content and simple java Maps/Lists.
Expand Down Expand Up @@ -52,8 +48,8 @@ public void writeCollection(Collection<Object> collection, JsonGenerator jsonGen
}

/**
* Parse the json and return as a Map additionally specifying if the returned map should
* be modify aware meaning that it can detect when it has been modified.
* Parse the json and return as a Map additionally specifying if the returned map should be modify
* aware meaning that it can detect when it has been modified.
*/
@Override
public Map<String, Object> parseObject(String json, boolean modifyAware) throws IOException {
Expand Down Expand Up @@ -94,9 +90,8 @@ public Map<String, Object> parseObject(JsonParser parser) throws IOException {

/**
* Parse the json and return as a Map taking a JsonParser and a starting token.
* <p>
* Used when the first token is checked to see if the value is null prior to calling this.
* </p>
*
* <p>Used when the first token is checked to see if the value is null prior to calling this.
*/
@Override
public Map<String, Object> parseObject(JsonParser parser, JsonToken token) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
import java.io.IOException;
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 java.util.*;

final class EJsonReader {

static final JsonFactory json = new JsonFactory();
private final JsonParser parser;
private final boolean modifyAware;
private final ModifyAwareFlag modifyAwareOwner;
private int depth;
private Stack stack;
private Context currentContext;

EJsonReader(JsonParser parser, boolean modifyAware) {
this.parser = parser;
this.modifyAware = modifyAware;
this.modifyAwareOwner = modifyAware ? new ModifyAwareFlag() : null;
}

@SuppressWarnings("unchecked")
static Map<String, Object> parseObject(String json, boolean modifyAware) throws IOException {
Expand Down Expand Up @@ -102,24 +110,6 @@ static Object parse(JsonParser parser, JsonToken token, boolean modifyAware) thr
return new EJsonReader(parser, modifyAware).parseJson(token);
}

private final JsonParser parser;

private final boolean modifyAware;

private final ModifyAwareFlag modifyAwareOwner;

private int depth;

private Stack stack;

private Context currentContext;

EJsonReader(JsonParser parser, boolean modifyAware) {
this.parser = parser;
this.modifyAware = modifyAware;
this.modifyAwareOwner = (modifyAware) ? new ModifyAwareFlag() : null;
}

private void startArray() {
depth++;
stack.push(currentContext);
Expand Down Expand Up @@ -197,7 +187,6 @@ private Object parseJson(JsonToken token) throws IOException {
*/
private void processJsonToken(JsonToken token) throws IOException {
switch (token) {

case START_ARRAY:
startArray();
break;
Expand Down Expand Up @@ -273,17 +262,17 @@ private boolean isEmpty() {
}
}

private static abstract class Context {
private abstract static class Context {
Context next;

abstract void popContext(Context temp);

abstract Object getValue();

abstract void setKey(String key);

abstract void setValue(Object value);

abstract void setKey(String key);

abstract void setValueNull();
}

Expand Down Expand Up @@ -312,13 +301,13 @@ Object getValue() {
}

@Override
void setKey(String key) {
this.key = key;
void setValue(Object value) {
map.put(key, value);
}

@Override
void setValue(Object value) {
map.put(key, value);
void setKey(String key) {
this.key = key;
}

@Override
Expand Down Expand Up @@ -364,5 +353,4 @@ void setKey(String key) {
// not expected
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ final class EJsonWriter {
* Base jsonFactory implementation used when it is not passed in.
*/
static final JsonFactory jsonFactory = new JsonFactory();
private final JsonGenerator jsonGenerator;

private EJsonWriter(JsonGenerator jsonGenerator) {
this.jsonGenerator = jsonGenerator;
}

static String write(Object object) throws IOException {
StringWriter writer = new StringWriter(200);
Expand All @@ -42,12 +47,6 @@ static void writeCollection(Collection<Object> collection, JsonGenerator jsonGen
new EJsonWriter(jsonGenerator).writeCollection(null, collection);
}

private final JsonGenerator jsonGenerator;

private EJsonWriter(JsonGenerator jsonGenerator) {
this.jsonGenerator = jsonGenerator;
}

private void writeJson(Object object) {
writeJson(null, object);
}
Expand Down Expand Up @@ -210,5 +209,4 @@ private void writeMap(String name, Map<Object, Object> map) throws IOException {
}
jsonGenerator.writeEndObject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ public boolean isMarkedDirty() {
public void setMarkedDirty(boolean markedDirty) {
this.markedDirty = markedDirty;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public final class ModifyAwareIterator<E> implements Iterator<E> {

/**
* Create with an Owner and the underlying Iterator this wraps.
* <p>
* The owner is notified of the removals.
* </p>
*
* <p>The owner is notified of the removals.
*/
public ModifyAwareIterator(ModifyAwareType owner, Iterator<E> it) {
this.owner = owner;
Expand All @@ -38,5 +37,4 @@ public void remove() {
owner.setMarkedDirty(true);
it.remove();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public String toString() {
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof ModifyAwareMap) {
ModifyAwareMap<?,?> that = (ModifyAwareMap<?,?>) o;
ModifyAwareMap<?, ?> that = (ModifyAwareMap<?, ?>) o;
return Objects.equals(map, that.map);
}
if (!(o instanceof Map)) return false;
Map<?,?> that = (Map<?,?>) o;
Map<?, ?> that = (Map<?, ?>) o;
return Objects.equals(map, that);
}

Expand Down Expand Up @@ -112,7 +112,6 @@ public void putAll(Map<? extends K, ? extends V> m) {
map.putAll(m);
}


@Override
public void clear() {
if (!map.isEmpty()) {
Expand All @@ -135,5 +134,4 @@ public Collection<V> values() {
public Set<Map.Entry<K, V>> entrySet() {
return new ModifyAwareSet<>(this, map.entrySet());
}

}
9 changes: 9 additions & 0 deletions ebean-core-json/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module io.ebean.core.json {

requires io.ebean.api;

requires transitive com.fasterxml.jackson.core;
exports io.ebeaninternal.json to io.ebean.test, io.ebean.core;

provides io.ebean.service.BootstrapService with io.ebeaninternal.json.DJsonService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.ebeaninternal.json.DJsonService
6 changes: 6 additions & 0 deletions ebean-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<version>16.0.0-RC3</version>
</dependency>

<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-json</artifactId>
<version>16.0.0-RC3</version>
</dependency>

<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-runner</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions ebean-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
requires io.ebean.types;

requires static io.avaje.jsr305x;
requires static io.ebean.core.json;
requires static com.fasterxml.jackson.annotation;
requires static com.fasterxml.jackson.core;
requires static com.fasterxml.jackson.databind;
Expand All @@ -49,7 +50,6 @@

exports io.ebeaninternal.api to io.ebean.ddl.generator, io.ebean.querybean, io.ebean.autotune, io.ebean.postgis, io.ebean.test, io.ebean.elastic, io.ebean.spring.txn, io.ebean.postgis.types;
exports io.ebeaninternal.api.json to io.ebean.test;
exports io.ebeaninternal.json to io.ebean.test;
exports io.ebeaninternal.server.autotune to io.ebean.autotune;
exports io.ebeaninternal.server.core to io.ebean.test, io.ebean.elastic;
exports io.ebeaninternal.server.core.bootup to io.ebean.test;
Expand Down Expand Up @@ -78,7 +78,6 @@
io.ebeaninternal.server.query.DFetchGroupService,
io.ebeaninternal.server.profile.DProfileLocationFactory,
io.ebeaninternal.server.rawsql.DRawSqlService,
io.ebeaninternal.server.profile.DMetricFactory,
io.ebeaninternal.json.DJsonService;
io.ebeaninternal.server.profile.DMetricFactory;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ io.ebeaninternal.server.rawsql.DRawSqlService
io.ebeaninternal.server.query.DFetchGroupService
io.ebeaninternal.server.profile.DProfileLocationFactory
io.ebeaninternal.server.profile.DMetricFactory
io.ebeaninternal.json.DJsonService
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<module>ebean-jackson-mapper</module>
<module>ebean-spring-txn</module>
<module>kotlin-querybean-generator</module>
<module>ebean-core-json</module>
</modules>

<profiles>
Expand Down