-
Notifications
You must be signed in to change notification settings - Fork 417
Gh680 jsonproviders no auto start #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca1ed56
No auto-start of JsonProviders + remaining chars after reading JSON s…
brenuart 3d480cf
Don't complain if the JSON pattern is empty but default to noop
brenuart a3dea51
Review error message
brenuart e35ce6c
Create parser on the trimmed input JSON
brenuart 7abc413
Add "for internal use only" notice in class javadoc
brenuart 8a9b52e
Remove unused methods from JsonReadingUtils
brenuart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/net/logstash/logback/composite/JsonReadingUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Copyright 2013-2021 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package net.logstash.logback.composite; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonFactory; | ||
| import com.fasterxml.jackson.core.JsonParseException; | ||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
|
||
| /** | ||
| * Utilities for reading/parsing JSON string. | ||
| * | ||
| * <p>Note: This class is for internal use only and subject to backward incompatible change | ||
| * at any time. | ||
| * | ||
| * @author brenuart | ||
| */ | ||
| public class JsonReadingUtils { | ||
|
|
||
| private JsonReadingUtils() { | ||
| // utility class - prevent instantiation | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Fully read the supplied JSON string into the equivalent {@link JsonNode}. | ||
| * | ||
| * Throws a {@link JsonParseException} if the string is not fully read after a first valid JsonNode is found. | ||
| * This may happen for input like <em>10 foobar</em> that would otherwise return a NumericNode with value | ||
| * {@code 10} leaving <em>foobar</em> unread. | ||
| * | ||
| * @param jsonFactory the {@link JsonFactory} from which to obtain a {@link JsonParser} to read the JSON string. | ||
| * @param json the JSON string to read | ||
| * @return the {@link JsonNode} corresponding to the input string or {@code null} if the string is null or empty. | ||
| * @throws IOException if there is either an underlying I/O problem or decoding issue | ||
| */ | ||
| public static JsonNode readFully(JsonFactory jsonFactory, String json) throws IOException { | ||
| if (json == null) { | ||
| return null; | ||
| } | ||
|
|
||
| final String trimmedJson = json.trim(); | ||
| try (JsonParser parser = jsonFactory.createParser(trimmedJson)) { | ||
| final JsonNode tree = parser.readValueAsTree(); | ||
|
|
||
| if (parser.getCurrentLocation().getCharOffset() < trimmedJson.length()) { | ||
| /* | ||
| * If the full trimmed string was not read, then the full trimmed string contains a json value plus other text. | ||
| * For example, trimmedValue = '10 foobar', or 'true foobar', or '{"foo","bar"} baz'. | ||
| * In these cases readTree will only read the first part, and will not read the remaining text. | ||
| */ | ||
| throw new JsonParseException(parser, "unexpected character"); | ||
| } | ||
|
|
||
| return tree; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Fully read a JSON string into an {@link ObjectNode}, throwing a {@link JsonParseException} if the supplied string | ||
| * is not a valid JSON object representation. | ||
| * | ||
| * @param jsonFactory the {@link JsonFactory} from which to obtain a {@link JsonParser} to read the JSON string. | ||
| * @param json the JSON string to read | ||
| * @return the {@link JsonNode} corresponding to the input string or {@code null} if the string is null or empty. | ||
| * @throws IOException if there is either an underlying I/O problem or decoding issue | ||
| * | ||
| * @see JsonReadingUtils#readFully(JsonFactory, String) | ||
| */ | ||
| public static ObjectNode readFullyAsObjectNode(JsonFactory jsonFactory, String json) throws IOException { | ||
| final JsonNode node = readFully(jsonFactory, json); | ||
|
|
||
| if (node != null && !(node instanceof ObjectNode)) { | ||
| throw new JsonParseException(null, "expected a JSON object representation"); | ||
| } | ||
|
|
||
| return (ObjectNode) node; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.