Giter Site home page Giter Site logo

Polymorphic Type Handling about gwt-jackson HOT 5 CLOSED

nmorel avatar nmorel commented on July 29, 2024
Polymorphic Type Handling

from gwt-jackson.

Comments (5)

BenDol avatar BenDol commented on July 29, 2024

Is this different to using JsonTypeInfo?
I have this working for myself like so:

  • Location -> DomainObject
  • Site -> DomainObject
  • Area -> DomainObject
@JsonTypeInfo( use = JsonTypeInfo.Id.CLASS )
public abstract class DomainObject implements Serializable, IsSerializable {

    public abstract int getId();

    public abstract void setId(int id);
}

So I can have the return type as DomainObject and it will be deserialized as whatever child object that is passed across the wire. Not 100% sure if this is what you are talking about here though.

 {
    "@class":"nz.co.doltech.ims.shared.domains.Location",
    "id":1,
    "name":"Mt Maunganui",
    "description":"Mt Maunganui description here!",
    "order":0,
    "removed":false,
    "sites":[

    ],
    "displayName":"Mt Maunganui",
    "orderValue":0
 }

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

As Ben said, @JsonTypeInfo is already supported.

Global default typing is not but you can achieve something almost similar by using mix in annotations and add @JsonTypeInfo directly to Object.

from gwt-jackson.

reinert avatar reinert commented on July 29, 2024

Nice. @JsonSubTypes is also supported? Like the pattern below:

@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type")
@JsonSubTypes({
        @JsonSubTypes.Type(value=Dog.class, name="DOG"),
        @JsonSubTypes.Type(value=Cat.class, name="CAT"),
})
public interface Animal {
    ...
}

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

Yes it is
Le 11 nov. 2014 17:30, "Danilo Reinert" [email protected] a Γ©crit :

Nice. @JsonSubTypes is also supported? Like the pattern below:

@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type")
@JsonSubTypes({
@JsonSubTypes.Type(value=Dog.class, name="DOG"),
@JsonSubTypes.Type(value=Cat.class, name="CAT"),
})public interface Animal {
...
}

β€”
Reply to this email directly or view it on GitHub
#36 (comment).

from gwt-jackson.

reinert avatar reinert commented on July 29, 2024

Thanks!

from gwt-jackson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.