-
Notifications
You must be signed in to change notification settings - Fork 275
Jackson 3 support #1074
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
Draft
l-trotta
wants to merge
8
commits into
main
Choose a base branch
from
jackson3-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Jackson 3 support #1074
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
882bb18
add jackson 3 support
l-trotta 3db02ee
updated unit tests
l-trotta 08319c8
fix test
l-trotta c029439
removed comment
l-trotta e2a29af
add comment on broken test
l-trotta e701299
deprecate jackson 2 classes
l-trotta 1b8be67
Catch parsing exceptions to convert them to JsonP's JsonParsingException
swallez 2dfa1df
Jackson 3 does work :-)
swallez 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
113 changes: 113 additions & 0 deletions
113
java-client/src/main/java/co/elastic/clients/json/jackson/Jackson3JsonBuffer.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,113 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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 co.elastic.clients.json.jackson; | ||
|
||
import co.elastic.clients.json.JsonBuffer; | ||
import co.elastic.clients.json.JsonData; | ||
import co.elastic.clients.json.JsonpDeserializer; | ||
import co.elastic.clients.json.JsonpMapper; | ||
import co.elastic.clients.json.JsonpUtils; | ||
|
||
import jakarta.json.JsonValue; | ||
import jakarta.json.stream.JsonGenerator; | ||
import jakarta.json.stream.JsonParser; | ||
import tools.jackson.databind.util.TokenBuffer; | ||
|
||
import java.io.StringWriter; | ||
import java.lang.reflect.Type; | ||
|
||
class Jackson3JsonBuffer implements JsonBuffer, JsonData { | ||
private final TokenBuffer buffer; | ||
private final Jackson3JsonpMapper mapper; | ||
|
||
Jackson3JsonBuffer(TokenBuffer buffer, Jackson3JsonpMapper mapper) { | ||
this.buffer = buffer; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public JsonParser asParser() { | ||
return new Jackson3JsonpParser(buffer.asParser(), mapper); | ||
} | ||
|
||
@Override | ||
public JsonValue toJson() { | ||
try (JsonParser parser = asParser()) { | ||
parser.next(); // move to first event | ||
return parser.getValue(); | ||
} | ||
} | ||
|
||
@Override | ||
public JsonValue toJson(JsonpMapper mapper) { | ||
// We don't need the mapper | ||
return toJson(); | ||
} | ||
|
||
@Override | ||
public <T> T to(Type type) { | ||
return to(type, this.mapper); | ||
} | ||
|
||
@Override | ||
public <T> T to(Type type, JsonpMapper mapper) { | ||
try (JsonParser parser = asParser()) { | ||
return mapper.deserialize(parser, type); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> T deserialize(JsonpDeserializer<T> deserializer) { | ||
return deserialize(deserializer, this.mapper); | ||
} | ||
|
||
@Override | ||
public <T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper) { | ||
try (JsonParser parser = asParser()) { | ||
return deserializer.deserialize(parser, mapper); | ||
} | ||
} | ||
|
||
@Override | ||
public void serialize(JsonGenerator generator, JsonpMapper mapper) { | ||
if (generator instanceof Jackson3JsonpGenerator) { | ||
Jackson3JsonpGenerator jkGenerator = (Jackson3JsonpGenerator) generator; | ||
buffer.serialize(jkGenerator.jacksonGenerator()); | ||
} else { | ||
try (JsonParser parser = asParser()) { | ||
JsonpUtils.copy(parser, generator); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Renders this buffer as a JSON string for debugger and logging convenience. | ||
*/ | ||
@Override | ||
public String toString() { | ||
StringWriter writer = new StringWriter(); | ||
try (Jackson3JsonpGenerator generator = | ||
new Jackson3JsonpGenerator(mapper.objectMapper().createGenerator(writer))) { | ||
serialize(generator, mapper); | ||
generator.close(); | ||
return writer.toString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation("com.fasterxml.jackson.core","jackson-annotations","3.0-rc5")
dedicated jackson-annotations for version 3 is dropped.
from jackson discussion FasterXML/jackson-future-ideas#90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know, thank you! will fix