Skip to content

Commit

Permalink
Keep exsiting behavior when using objectMapper.readTree() with empty …
Browse files Browse the repository at this point in the history
…values

FasterXML/jackson-databind#2211
- In Jackson <2.9.0 an IOException was raised
- In Jackson >=2.9.0, null is returned
  • Loading branch information
mpfz0r committed Aug 19, 2019
1 parent 8e9eeef commit 474fdb6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ public Message decode(@Nonnull RawMessage rawMessage) {
final JsonNode event;
try {
event = objectMapper.readTree(payload);
if (event == null) {
throw new IOException("null result");
}
} catch (IOException e) {
LOG.error("Couldn't decode raw message {}", rawMessage);
return null;
}

// Adhere to the legacy behaviour
if (event == null) {
return null;
}

return parseEvent(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public JsonParse(ObjectMapper objectMapper) {
public JsonNode evaluate(FunctionArgs args, EvaluationContext context) {
final String value = valueParam.required(args, context);
try {
return objectMapper.readTree(value);
final JsonNode node = objectMapper.readTree(value);
if (node == null) {
throw new IOException("null result");
}
return node;
} catch (IOException e) {
log.warn("Unable to parse JSON", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

Expand Down Expand Up @@ -127,6 +128,9 @@ public Message decode(@Nonnull final RawMessage rawMessage) {

try {
node = objectMapper.readTree(json);
if (node == null) {
throw new IOException("null result");
}
} catch (final Exception e) {
log.error("Could not parse JSON, first 400 characters: " +
StringUtils.abbreviate(json, 403), e);
Expand Down
3 changes: 3 additions & 0 deletions graylog2-server/src/main/java/org/graylog2/plugin/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ public static Optional<AbsoluteRange> extractHistogramBoundaries(final String qu
try {
final JsonParser jp = OBJECT_MAPPER.getFactory().createParser(query);
final JsonNode rootNode = OBJECT_MAPPER.readTree(jp);
if (rootNode == null) {
throw new IOException("null result");
}
final JsonNode timestampNode = rootNode.findValue("range").findValue("timestamp");
final String from = elasticSearchTimeFormatToISO8601(timestampNode.findValue("from").asText());
final String to = elasticSearchTimeFormatToISO8601(timestampNode.findValue("to").asText());
Expand Down

0 comments on commit 474fdb6

Please sign in to comment.