Skip to content

Commit a7690cd

Browse files
committed
Replace buggy .readOne() methods with JsonNodeReader from coreutils
1 parent 4bc689d commit a7690cd

File tree

3 files changed

+12
-64
lines changed

3 files changed

+12
-64
lines changed

src/main/java/com/github/fge/jsonschema/process/Index.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717

1818
package com.github.fge.jsonschema.process;
1919

20-
import com.fasterxml.jackson.core.JsonLocation;
21-
import com.fasterxml.jackson.core.JsonParseException;
22-
import com.fasterxml.jackson.core.JsonParser;
2320
import com.fasterxml.jackson.core.JsonProcessingException;
2421
import com.fasterxml.jackson.databind.JsonNode;
25-
import com.fasterxml.jackson.databind.MappingIterator;
26-
import com.fasterxml.jackson.databind.ObjectMapper;
2722
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
2823
import com.fasterxml.jackson.databind.node.ObjectNode;
2924
import com.github.fge.jackson.JacksonUtils;
25+
import com.github.fge.jackson.JsonNodeReader;
3026
import com.github.fge.jsonschema.constants.ParseError;
3127
import com.github.fge.jsonschema.core.report.ProcessingReport;
3228
import com.github.fge.jsonschema.core.util.AsJson;
@@ -56,7 +52,8 @@ public final class Index
5652
private static final Response OOPS = Response.status(500).build();
5753
private static final JsonValidator VALIDATOR
5854
= JsonSchemaFactory.byDefault().getValidator();
59-
private static final ObjectMapper MAPPER = JacksonUtils.newMapper();
55+
private static final JsonNodeReader NODE_READER
56+
= new JsonNodeReader();
6057

6158
@POST
6259
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@@ -117,35 +114,11 @@ private static boolean fillWithData(final ObjectNode node,
117114
throws IOException
118115
{
119116
try {
120-
node.put(onSuccess, readOne(raw));
117+
node.put(onSuccess, NODE_READER.fromReader(new StringReader(raw)));
121118
return false;
122119
} catch (JsonProcessingException e) {
123120
node.put(onFailure, ParseError.build(e, raw.contains("\r\n")));
124121
return true;
125122
}
126123
}
127-
128-
private static JsonNode readOne(final String input)
129-
throws IOException
130-
{
131-
final MappingIterator<JsonNode> iterator;
132-
final JsonNode ret;
133-
final JsonLocation location;
134-
135-
try (
136-
final StringReader reader = new StringReader(input);
137-
final JsonParser parser = MAPPER.getFactory().createParser(reader);
138-
) {
139-
iterator = MAPPER.readValues(parser, JsonNode.class);
140-
if (!iterator.hasNextValue())
141-
throw new JsonParseException("no data",
142-
new JsonLocation(reader, 0L, 1, 1));
143-
ret = iterator.nextValue();
144-
location = parser.getCurrentLocation();
145-
if (!iterator.hasNextValue())
146-
return ret;
147-
throw new JsonParseException("extra data after first node",
148-
location);
149-
}
150-
}
151124
}

src/main/java/com/github/fge/jsonschema/process/JsonPatch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
2929
import com.fasterxml.jackson.databind.node.ObjectNode;
3030
import com.github.fge.jackson.JacksonUtils;
31-
import com.github.fge.jackson.JsonLoader;
31+
import com.github.fge.jackson.JsonNodeReader;
3232
import com.github.fge.jsonpatch.JsonPatchInput;
3333
import com.github.fge.jsonpatch.JsonPatchProcessor;
3434
import com.github.fge.jsonschema.constants.ParseError;
@@ -62,6 +62,8 @@ public final class JsonPatch
6262
private static final JsonPatchProcessor PROCESSOR
6363
= new JsonPatchProcessor();
6464
private static final ObjectMapper MAPPER = JacksonUtils.newMapper();
65+
private static final JsonNodeReader NODE_READER
66+
= new JsonNodeReader();
6567

6668
@POST
6769
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@@ -125,7 +127,7 @@ private static boolean fillWithData(final ObjectNode node,
125127
throws IOException
126128
{
127129
try {
128-
node.put(onSuccess, JsonLoader.fromString(raw));
130+
node.put(onSuccess, NODE_READER.fromReader(new StringReader(raw)));
129131
return false;
130132
} catch (JsonProcessingException e) {
131133
node.put(onFailure, ParseError.build(e, raw.contains("\r\n")));

src/main/java/com/github/fge/jsonschema/process/Processing.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package com.github.fge.jsonschema.process;
22

33

4-
import com.fasterxml.jackson.core.JsonLocation;
5-
import com.fasterxml.jackson.core.JsonParseException;
6-
import com.fasterxml.jackson.core.JsonParser;
74
import com.fasterxml.jackson.core.JsonProcessingException;
85
import com.fasterxml.jackson.databind.JsonNode;
9-
import com.fasterxml.jackson.databind.MappingIterator;
10-
import com.fasterxml.jackson.databind.ObjectMapper;
116
import com.fasterxml.jackson.databind.node.ArrayNode;
127
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
138
import com.fasterxml.jackson.databind.node.ObjectNode;
149
import com.github.fge.jackson.JacksonUtils;
10+
import com.github.fge.jackson.JsonNodeReader;
1511
import com.github.fge.jsonschema.constants.ParseError;
1612
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
1713
import com.github.fge.jsonschema.core.report.ProcessingMessage;
@@ -32,7 +28,8 @@
3228
public abstract class Processing
3329
{
3430
private static final Response OOPS = Response.status(500).build();
35-
private static final ObjectMapper MAPPER = JacksonUtils.newMapper();
31+
private static final JsonNodeReader NODE_READER
32+
= new JsonNodeReader();
3633

3734
protected static final JsonNodeFactory FACTORY = JacksonUtils.nodeFactory();
3835

@@ -69,7 +66,7 @@ protected static boolean fillWithData(final ObjectNode node,
6966
throws IOException
7067
{
7168
try {
72-
node.put(onSuccess, readOne(raw));
69+
node.put(onSuccess, NODE_READER.fromReader(new StringReader(raw)));
7370
return false;
7471
} catch (JsonProcessingException e) {
7572
node.put(onFailure, ParseError.build(e, raw.contains("\r\n")));
@@ -84,28 +81,4 @@ protected static JsonNode buildReport(final ProcessingReport report)
8481
ret.add(message.asJson());
8582
return ret;
8683
}
87-
88-
private static JsonNode readOne(final String input)
89-
throws IOException
90-
{
91-
final MappingIterator<JsonNode> iterator;
92-
final JsonNode ret;
93-
final JsonLocation location;
94-
95-
try (
96-
final StringReader reader = new StringReader(input);
97-
final JsonParser parser = MAPPER.getFactory().createParser(reader);
98-
) {
99-
iterator = MAPPER.readValues(parser, JsonNode.class);
100-
if (!iterator.hasNextValue())
101-
throw new JsonParseException("no data",
102-
new JsonLocation(reader, 0L, 1, 1));
103-
ret = iterator.nextValue();
104-
location = parser.getCurrentLocation();
105-
if (!iterator.hasNextValue())
106-
return ret;
107-
throw new JsonParseException("extra data after first node",
108-
location);
109-
}
110-
}
11184
}

0 commit comments

Comments
 (0)