Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:38
    the-codinator opened #3184
  • 06:59
    CodingFabian commented #3182
  • 06:21
    joschi edited #2960
  • 06:21
    joschi synchronize #2960
  • 06:20
    joschi commented #2960
  • 06:17
    joschi synchronize #2960
  • 06:10
    joschi synchronize #2960
  • 06:07
    joschi synchronize #2960
  • 03:06
    cowtowncoder commented #2960
  • 03:04
    cowtowncoder commented #2960
  • 03:03

    cowtowncoder on master

    Test push to trigger (I hope) T… Remove ppc build from Travis: w… Add `mvnw` wrapper and 1 more (compare)

  • 03:02

    cowtowncoder on 2.13

    Add `mvnw` wrapper (compare)

  • 01:49
    cowtowncoder commented #3182
  • 01:14
    cowtowncoder commented #2960
  • Jun 23 23:27
    cowtowncoder closed #2574
  • Jun 23 23:27
    cowtowncoder commented #2574
  • Jun 23 22:22
    cowtowncoder commented #2960
  • Jun 23 22:19
    cowtowncoder closed #3134
  • Jun 23 22:19
    cowtowncoder commented #3134
  • Jun 23 21:26
    cowtowncoder commented #3183
Marvin
@RealMarvn
uhm can someone help me?
I wanna read this XML but I am not able. It gives me everytime null in my String and If it works...Its the wrong value (title is multiple times in that xml). Can someone maby add me on Discord and help me with that xml problem?
Raghu Dinka Vijaykumar
@raghudinkavijaykumar

Here is the POJO i am using

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class FileTypes implements Serializable {
    private static final long serialVersionUID = 1L;
    @JsonProperty(required = true)
    private FileType name;
    private String status;
    private String namingStrategy;
}

I am mapping Map<String, String> to List<FileTypes>.

 ObjectMapper mapper = new ObjectMapper();
 List<FileTypes> files = mapper.convertValue(newMap, new TypeReference<List<FileTypes>>() {
            });

enter image description here

I am getting the below exception

Cannot deserialize value of type `java.util.ArrayList<>` from Object value (token `JsonToken.START_OBJECT`)
Deserialize Map<String, String> to value of type ArrayList<Object>
is this possible?
Tatu Saloranta
@cowtowncoder
@raghudinkavijaykumar in general, no, Arrays/Lists and Maps have different structure -- one is a sequence of unnamed values, another a set of key/value pairs
Raghu Dinka Vijaykumar
@raghudinkavijaykumar
@cowtowncoder Thanks.
Zane XiaoYe
@Zane-XY
Hi, is there a way to make JsonCreator annotation inheritable or programable? I have a base class which has over 100 implementations.
I need to add the @JsonCreator annotation to all the sub classes. How can I do this one time if all the sub classes have the same contructor signature?
3 replies
one way I could think of is to create a base mixin class with @JsonCreator configuration, and register all the sub-classes to use this mixin configuration, but haven’t tested, I don’t know if it has any bad side effects.
1 reply
Zane XiaoYe
@Zane-XY

Hi,
i have custom serializer which extends StdSerializer. Inside the serializer, I need some extra parameters to do the the serialization, for example:

class A {
private int id;
private B b;
}

i have a custom serializer for B, is it possible to pass A.id to the serializer?

11 replies
Zane XiaoYe
@Zane-XY

Hi, If I want to add a constructor Mixin, would the implementation itself matter? or it just read the annotation configurations?

public abstract class UserDTOConstructorMixIn extends User  {

  @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
  public UserDTOConstructorMixIn(@JsonProperty("userId") Long userId, @JsonProperty("userName") String username) {
    super(userId, username);
  }
}

In my case I want to use this mixin class for several subclasses which have the same constructor signature, but their implementations are slightly different.

2 replies
DaGeRe
@DaGeRe
Hi, are there performance measurements of the performance tests in https://github.com/FasterXML/jackson-databind/tree/master/src/test/java/perf available somewhere, or are they only executed manually? I'm currently trying to develop a technique for measuring the performance of unit tests and would like to compare the regressions identified by unit test measurements to the regressions found by manually defined performance tests.
Andriy Plokhotnyuk
@plokhotnyuk
@DaGeRe AFAIK for performance tests on JVM the best option is to use JMH. jmh-gradle-plugin and sbt-jmh allow easily run benchmarks with different profilers and visualize results using JMH Visualizer to easily spot the difference.
DaGeRe
@DaGeRe
@plokhotnyuk Thats right, but I do not want to write performance tests, but to compare measurement results of existing benchmarks (like the one from jackson-databind) to performance measurements of unit tests (for research). Therefore, I need measurement data from existing commits, but I suspect these are not available for jackson-databind or other parts of jackson..
DaGeRe
@DaGeRe
Thanks! This seems very comprehensive, I'll have a deeper look at this. For my evaluation, I would need to compare this to Java unit tests, but since jackson-module-scala is based on jackson-core, it is likely that the measurements also contain regressions caused by jackson-core, or is this assumption wrong?
And to get regressions, I would need to parse the json-files of every individual version, or are there some aggregated values? For a first try, I did for commit in $(git log --pretty=format:"%h" | head -n 15); do git checkout $commit; echo -n "$commit " >> vals.csv; grep "ADTReading.avSystemGenCodec" corretto-11.json -A 40 | grep "score\"\|scoreError" | awk '{print $3}' | tr ",\n" " " >> vals.csv; echo >> vals.csv; done, which is not very nice but seems to work.
Andriy Plokhotnyuk
@plokhotnyuk
@DaGeRe It is great that historical data have a chance to be used! Last year for all benchmarks each run was on the same hardware and usually took 1-2 days form start to publishing. Updates of libraries are in build.sbt. Changes of JVM options are in CommonParams.scala. Also there is a history records of unit tests for jsoniter-scala itself on per commit basis. It is available on the GitHub Actions page of the project. Each unit test reports its name and elapsed time in millis:
Andriy Plokhotnyuk
@plokhotnyuk
image.png
Tatu Saloranta
@cowtowncoder
On jackson-databind benchmarks: those are manually run and only occasionally. Once I run more often, based on jmh, are at: https://github.com/FasterXML/jackson-benchmarks
but so far I haven't figured out a good way to automate these; part is wrt dedicated hardware (container-based testing seems problematic for stable results), but maybe bigger is question of how to actually visualize results across formats, jackson versions etc.
one thing worth noting is that Scala module performance is probably quite specific to Scala -- whereas core components have focused quite a bit on performance, my impression is that much of Scala module functionality (and to a degree Kotlin too) is only focused on functional correctness and I'd expect quite a bit of room for improvements. Meaning that performance of types Scala/Kotlin module handle is probably lower than that of POJOs. Then again there some annotations in databind have a clear performance overhead (use of argument-taking constructors is slower than use of field/setter approach)
@DaGeRe just one note: I have never tried to write unit tests for tracking performance as I doubt that would prove reliable on typical on-demand CI/CD systems -- seems to me that doing that would be useful, but would also require much stricter definition of runtime platform to ensure consistent performance. Plus JDK versions can have significant impact (not often but sometimes) beyond library being tested.
Zane XiaoYe
@Zane-XY
does the @JsonCreator support overloaded constructors?
2 replies
I have a class with many overloaded constructors, how do I tell Jackson which one to choose with different payload?
DaGeRe
@DaGeRe
@plokhotnyuk Thanks for the hint! I've wrote two simple scripts to get an overview over the measurement data trend: https://github.com/DaGeRe/performance-analysis-jackson Thereby, I can get graphs like https://github.com/DaGeRe/performance-analysis-jackson/blob/main/com.github.plokhotnyuk.jsoniter_scala.benchmark.ADTReading.avSystemGenCodec.csv.pdf
Do I see it correctly that you always run one fork? With one fork, it's hard to identify a performance change (with statistic rigor), since random effects during initialization of the JVM may cause different performance behaviour.
And are the performance changes somehow traceable, or did you just execute the measurements and then on occasion fix regressions? For example the measurement in c31e99ab seems to contain a regression in ADTReading.avSystemGenCodec, which is fixed afterwards, is there a way of tracing this with the data (beyond manually inspecting all commits between 7th and 13th of January)?
DaGeRe
@DaGeRe
@cowtowncoder The current research state in this context is that duet benchmarking, i.e. parallel execution of the current and predecessing versions, will help yielding reliable performance measurements (https://arxiv.org/abs/2001.05811), and for sure more repetitions of the benchmark also helps. You could just do this with the existing jmh-benchmarks. Surely, the used JVM will always matter.
Using the pure unit tests will not yield reliable values (due to warmup etc.), hence, I am developing a tool for just reusing a subset of the unit tests for performance measurement (https://github.com/DaGeRe/peass-ci). Therefore, I am searching for a set of regressions / improvements, which are covered by regular benchmarks, so I can evaluate which share can be found using automatically transformed unit tests. So if there is something hidden in jackson which could be used for this evaluation I'd be glad.
Andriy Plokhotnyuk
@plokhotnyuk
The avSystemGenCodec is a name of library that parse JSON in this benchmark. To analyze jackson data you should select results which named jacksonScala in the end. And yes, it is not correct to run 1 fork, but you could apply some averaging to reduce spikes. As example for avSystemGenCodec there wasn't changes in the dependencies defined at build.sbt for that period, so probably it is just a random spike.
Tatu Saloranta
@cowtowncoder
@DaGeRe ah. That makes sense (Wrt dual runs, to replicate as similar as possible environment). I was thinking more of serial trends, where runs would be separated by other factors. And yes, agreed, "regular" unit tests not meant for testing performance would not be useful for all the usual reasons.
@DaGeRe anyway, I don't think I have written any junit-invoked performance tests. Jackson-benchmarks has bigger tests, via jmh. Once upon a time I did write https://github.com/FasterXML/jvm-json-benchmark but it's been years since I touched that.
@DaGeRe I'd be interested in this area: it's sort of chicken-and-egg issue: before having a setup that can produce useful comparison, there's little incentive to write tests. And vice versa. Also curious as to how the usual warmup challenges would be handled -- seems like these days a fixed warmup runtime can work ok if tuned on per-test basis (with jmh, 5 seconds often seems to suffice). So I could probably come up with tests, if there are some parameters/guidelines. And would probably find results useful. But unfortunately not sure anything that exists is useful ... except possibly manual tests you did find :)
Marc Magon
@GedMarc
Hey guys, How do I override the ObjectMapper instance that Jax-RS provider uses?
3 replies
Jay
@JayChandler
How can i avoid deserialization of null values for a Map<String, Object> in jackson 2.9. It seems JsonInclude.Include.NON_NULL only works for serialization!
3 replies
Bernd
@ecki
Hey, when ObjectMapper().readTree() is used to get a JSONNode representation, does this gurantee there are no type introspection or value evaluations used? Or are there still settings which should be turned off (2.9)?
11 replies
Bernd
@ecki
Would be probably a good idea to add a JSONNode based Tutorial section, its not really obvious that you need jackson-databind for "dom style" processing. Also I have seen a few times readValue(in, JsonNode.class) - is that sane?
2 replies
Alan Zimmer
@alzimmermsft

In Jackson 2.12 is it possible to configure MapSerializer to include entries with null values but to skip entries with null keys? What I'm finding is that Collections.singletonMap(null, null) results in an exception being thrown.

I've attempted both configuring the null key serializer to use the default null serializer (null -> null ([110, 117, 108, 108])) and adding a configuration override for Map.class to ignore null keys. The former fails due to a null key being used in the JSON but the latter fails because the generic path attempts to use the null key serializer before checking against the keys to ignore.

https://github.com/FasterXML/jackson-databind/blob/2.12/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java#L790

Is there another configuration that could used to prevent null key entries from being serialized?

5 replies
Jordan Finci
@finci-square
is there any super simple way to simply mark a field of a POJO to be serialized and the serialization value is a string containing the object serialized to JSON
4 replies
and then deserialized back the same way
Carter Kozak
@carterkozak
Hi friends, I've started investigating graalvm native-images for a few of my services, and reducing reflection can be helpful there. I've been thinking about building an annotation processor which produces both a jackson serializer and deserializer based on jackson annotations, which is able to interact directly with the target type for performance similar to afterburner/blackbird. Obviously interactions with private fields wouldn't work, and some configuration would either be unsupported or move to branching in the generated code, but otherwise it feels feasible.
I'm curious if this is something that has been attempted, or if there are potential issues I haven't considered?
13 replies
Harshit Agarwal
@Mysterious19

Hi! is there any separate channel for jackson-module-kotlin repo? I was trying to build the library locally and run testcase, but getting the following error:

jackson-module-kotlin/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt:37:18
Kotlin: Unresolved reference: PackageVersion

new to opensource and jackson

3 replies
Adam Nalisnick
@theadam
Is there a way to replace the deserializers for certain keys in a SimpleModule? I have some problematic scala types, that I can detect on my side, but I wanted to replace the deserializer for the keys where I detect those types.
1 reply
I tried to create a DeserializerModifier, then override updateBuilder, and use withValueDeserializer on some properties, but it did not seem to have an effect.
ToxicMushroom
@ToxicMushroom
Hi, I feel like its me doing being dumb instead of jackson so I decided to ask here first if someone knows what this implies: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
gist with full stacktrace: https://gist.github.com/ToxicMushroom/945178edc02d6724570b02a784056632
gist with string input: https://gist.github.com/ToxicMushroom/0167bce66910fbffba1ec7274fe8f368
Class that I'm trying to serialize: https://github.com/ToxicMushroom/Melijn/blob/master/src/main/kotlin/me/melijn/melijnbot/internals/models/EmbedEditor.kt
I'm using version 2.12.3 jackson-core, the error also mean much to me sadly, thanks in advance <3
13 replies
James Howe
@OrangeDog
Is there any situation where @JsonFormat works for serialization?
8 replies
Mikael Elm
@mickeelm
Is it possible to map a single JSON-field to multiple Java fields (I can describe the use case further if you wish)?
2 replies
Tatu Saloranta
@cowtowncoder
Anyone interested in knowing how 2.13.0-rc1 planning will go: I created this issue FasterXML/jackson#83 -- for discussion, updates etc.
dutchmahoney
@dutchmahoney
Hello. There are portions of the app I'm working on that use Jackson to deserialize JSON to types very deliberately (say to a User). I'm working on a different portion where I only want to allow serialization to types analogous to JSON primitives (String, numbers (I've found the features to force to BigInteger and BigDecimal), objects (Map), arrays (List), booleans, and null) while also avoiding any security concerns (such as using STRICT_DUPLICATE_DETECTION; perhaps using BLOCK_UNSAFE_POLYMORPHIC_BASE_TYPES, but not sure if it applies for my use case). Is there a tried-and-true way to accomplish this?
11 replies
Nikita
@Berehulia
I need to parse json using jackson:
String string = "{\"field\" : \" \\/ \"}";
JsonNode node = new ObjectMapper().readTree(string);
String result = node.toString();
System.out.println(result);
I expect this kind of output:
result == {"field":" \/ "}
But, I end up with:
result == {"field":" / "}
How can I receive output like this?
result == {"field":" \/ "}
4 replies
Pratik
@the-codinator
Hello, I'm using jackson-databind (2.12.3) to deserialize json to POJO. One of the fields has an alias, and I need to report an error if both, the field name and its alias are present in the json. Example:
POJO: class A { @JsonAlias("y") public int x; }
Input: { "x": 1, "y": 2 }
Output: A.x = 2
Expected Output: JsonMappingException
More detailed version of the question: https://stackoverflow.com/questions/68054902
4 replies
Jack Wilkinson
@guacjack
Hey all, i'm quite new to Jackson, i am deserialising using a default no-args constructor and setters (which i believe is the default method), however, when the json im deserialising does not contain a given value in the Java class i'm deserialising to is set to null. Is there a way to ensure that all fields in the Java class have to be present or fail the deserialisation?
4 replies