question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`JsonSubType.Type` should accept array of names

See original GitHub issue

While adding values to JsonSubTypes we have to add each element manually even if multiple keys map to same object.

example:

@JsonSubTypes({
        @JsonSubTypes.Type(name = "not_equals", value = NotEqualsExpression.class),
        @JsonSubTypes.Type(name = "ne", value = NotEqualsExpression.class),
        @JsonSubTypes.Type(name = "equals", value = EqualsExpression.class)
})
public abstract class Expression { ... }

Current implementation maps one class with one key whereas there are multiple keys in json which can map to same data-structure.

public @interface JsonSubTypes {
    JsonSubTypes.Type[] value();

    public @interface Type {
        Class<?> value();
        String name() default "";
    }
}

So as per the new feature multiple keys can be mapped to single data-structure without adding multiple entries.

public @interface JsonSubTypes {
    JsonSubTypes.Type[] value();

    public @interface Type {
        Class<?> value();
        String[] name() default "";
    }
}

Thoughts? If this is approved, I am also willing to contribute to this feature.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Jul 11, 2020

Merged, will be in 2.12.0.

1reaction
cowtowncodercommented, Jul 5, 2020

@swayamraina Ok it all looks good, and I am ready to merge changes. Just one last thing: before the first contribution (but only then), I’d need CLA:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

and the usual way is to print it, fill & sign, scan/photo, email to info at fasterxml dot com. Once I receive it, I can merge changes. CLA itself is good for all future contributions too, it’s just one-time thing we need.

Thank you again for contributing this improvement, looking forward to merging it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

com.fasterxml.jackson.annotation.JsonSubTypes$Type java ...
Id.NAME) @JsonSubTypes({ @Type(name = "I", value = Integer.class), @Type(name = "O", value = Double.class) }) // the annotation will be copied to a...
Read more >
JsonSubTypes, list of polymorpic objects and Parcelable
First things first: EXTERNAL_PROPERTY will only work when value is enclosed within another Object (POJO); and will not work for List s, ...
Read more >
Jackson Json - @JsonTypeInfo, using Logical Type Name ...
In that case we can use "logical type name" as use = JsonTypeInfo.Id.NAME. In that case name will then need to be separately...
Read more >
Type Handling Annotations in Jackson - Javatpoint
It is used for indicating subtypes of types annotated. The @JsonSubTypes annotation is used with @JsonTypeInfo annotation. Let's take an example to understand ......
Read more >
JsonTypeInfo “defaultImpl” for collections - Google Groups
Type (value = Dog.class, name = "dog"), @JsonSubTypes. ... It is working on an array at the time but somehow takes the suggestion...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found