-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(framework,actuator,common): replace fastjson with jackson #6701
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
Open
halibobo1205
wants to merge
9
commits into
tronprotocol:develop
Choose a base branch
from
halibobo1205:feat/jackjson
base: develop
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a24669
feat(framework,actuator,common): replace fastjson with jackson
halibobo1205 218c223
fix(test): remove trailing whitespace in GetDelegatedResourceAccountI…
halibobo1205 91d4745
test(framework): add buildTransaction test
halibobo1205 eb6d4eb
refactor(common): tighten TypeUtils visibility and drop unused casts
halibobo1205 2bb22cb
refactor(common): mark org.tron.json wrappers as @Deprecated
halibobo1205 d0ed2c4
refactor(common): drop unused JSONException(Throwable) constructor
halibobo1205 0116365
test(framework): expand org.tron.json wrapper test coverage
halibobo1205 669321a
feat(common,framework): cap JSON parse depth and token count
halibobo1205 bd32e36
fix(common): match Fastjson 1.x NaN/Infinity/NULL behavior
halibobo1205 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
67 changes: 11 additions & 56 deletions
67
actuator/src/main/java/org/tron/core/vm/trace/Serializers.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 |
|---|---|---|
| @@ -1,73 +1,28 @@ | ||
| package org.tron.core.vm.trace; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.JsonSerializer; | ||
| import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; | ||
| import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.SerializationFeature; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.fasterxml.jackson.databind.introspect.VisibilityChecker; | ||
| import java.io.IOException; | ||
| import com.fasterxml.jackson.databind.json.JsonMapper; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.bouncycastle.util.encoders.Hex; | ||
| import org.tron.common.runtime.vm.DataWord; | ||
| import org.tron.core.vm.Op; | ||
|
|
||
| @Slf4j(topic = "VM") | ||
| public final class Serializers { | ||
|
|
||
| public static String serializeFieldsOnly(Object value, boolean pretty) { | ||
| try { | ||
| ObjectMapper mapper = createMapper(pretty); | ||
| mapper.setVisibilityChecker(fieldsOnlyVisibilityChecker(mapper)); | ||
| private static final ObjectMapper mapper = JsonMapper.builder() | ||
| .enable(SerializationFeature.INDENT_OUTPUT) | ||
| .visibility(PropertyAccessor.FIELD, Visibility.ANY) | ||
| .visibility(PropertyAccessor.GETTER, Visibility.NONE) | ||
| .visibility(PropertyAccessor.IS_GETTER, Visibility.NONE) | ||
| .build(); | ||
|
|
||
| public static String serializeFieldsOnly(Object value) { | ||
| try { | ||
| return mapper.writeValueAsString(value); | ||
| } catch (Exception e) { | ||
| logger.error("JSON serialization error: ", e); | ||
| return "{}"; | ||
| } | ||
| } | ||
|
|
||
| private static VisibilityChecker<?> fieldsOnlyVisibilityChecker(ObjectMapper mapper) { | ||
| return mapper.getSerializationConfig().getDefaultVisibilityChecker() | ||
| .withFieldVisibility(JsonAutoDetect.Visibility.ANY) | ||
| .withGetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
| .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE); | ||
| } | ||
|
|
||
| public static ObjectMapper createMapper(boolean pretty) { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| if (pretty) { | ||
| mapper.enable(SerializationFeature.INDENT_OUTPUT); | ||
| } | ||
| return mapper; | ||
| } | ||
|
|
||
| public static class DataWordSerializer extends JsonSerializer<DataWord> { | ||
|
|
||
| @Override | ||
| public void serialize(DataWord energy, JsonGenerator jgen, SerializerProvider provider) | ||
| throws IOException, JsonProcessingException { | ||
| jgen.writeString(energy.value().toString()); | ||
| } | ||
| } | ||
|
|
||
| public static class ByteArraySerializer extends JsonSerializer<byte[]> { | ||
|
|
||
| @Override | ||
| public void serialize(byte[] memory, JsonGenerator jgen, SerializerProvider provider) | ||
| throws IOException, JsonProcessingException { | ||
| jgen.writeString(Hex.toHexString(memory)); | ||
| } | ||
| } | ||
|
|
||
| public static class OpCodeSerializer extends JsonSerializer<Byte> { | ||
|
|
||
| @Override | ||
| public void serialize(Byte op, JsonGenerator jgen, SerializerProvider provider) | ||
| throws IOException, JsonProcessingException { | ||
| jgen.writeString(Op.getNameOf(op)); | ||
| } | ||
| } | ||
| } |
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
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.
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.