Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Deserializing JSON to EMF(How to deserialize JSON into EMF using factories)
Deserializing JSON to EMF [message #1745954] Wed, 19 October 2016 18:42 Go to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 52
Registered: July 2016
Member
I am posting here out of desperation in hope that someone in the EMF community has solved this problem. The issue is not directly related to EMF but rather with the utility FasterXMLJackson.

When I serialize anything EMF using Jackson, it works and life is good. But not so the return trip. This is because for deserialization, Jackson wants a no-arg constructor by default and EMF ain't got one. To solve this, one can use one of Jackson's annotations @JsonCreator and create a "mixin". I did this but still no go. Here's what I have to date:

My mixin, which by all accounts seems correct.

public class PatientMixin {

    @JsonCreator
    public static ForecastPatient createForecastForecastPatient() {
        return ForecastFactory.eINSTANCE.createForecastPatient();
    }
}


Then we have to tell Jackson how to use it.

ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(ForecastPatient.class, PatientMixin.class);


It doesn't work. I get the same error I would get if I did none of this.

Surely someone has made EMF work with Jackson.

Thanks for your patience.
Re: Deserializing JSON to EMF [message #1745956 is a reply to message #1745954] Wed, 19 October 2016 19:33 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I have no experience with Jackson... Maybe it searches not for the interface to deserialize but the impl class, i.e. ForecastPatientImpl which your method does not have as return type?

BTW, Eclipse Texo has built-in support for serializing/deserializing EMF models for use in web services. It uses the org.json library, though.

Geoffry Roberts wrote on Wed, 19 October 2016 20:42
I am posting here out of desperation in hope that someone in the EMF community has solved this problem. The issue is not directly related to EMF but rather with the utility FasterXMLJackson.

When I serialize anything EMF using Jackson, it works and life is good. But not so the return trip. This is because for deserialization, Jackson wants a no-arg constructor by default and EMF ain't got one. To solve this, one can use one of Jackson's annotations @JsonCreator and create a "mixin". I did this but still no go. Here's what I have to date:

My mixin, which by all accounts seems correct.

public class PatientMixin {

    @JsonCreator
    public static ForecastPatient createForecastForecastPatient() {
        return ForecastFactory.eINSTANCE.createForecastPatient();
    }
}


Then we have to tell Jackson how to use it.

ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(ForecastPatient.class, PatientMixin.class);


It doesn't work. I get the same error I would get if I did none of this.

Surely someone has made EMF work with Jackson.

Thanks for your patience.

Re: Deserializing JSON to EMF [message #1746468 is a reply to message #1745954] Sun, 30 October 2016 09:07 Go to previous message
Guillaume Hillairet is currently offline Guillaume HillairetFriend
Messages: 97
Registered: July 2009
Member
You can try the emf-json jackson library, it will handle all that for you https://github.com/emfjson/emfjson-jackson
Previous Topic:Custom DataType for my emf editor
Next Topic:Read sequence diagram Xmi by EMF
Goto Forum:
  


Current Time: Thu Apr 25 16:05:42 GMT 2024

Powered by FUDForum. Page generated in 0.02514 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top