Skip to content
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

Type Id Handling not supported #46

Closed
stefanzilske opened this issue May 5, 2017 · 3 comments
Closed

Type Id Handling not supported #46

stefanzilske opened this issue May 5, 2017 · 3 comments

Comments

@stefanzilske
Copy link

Hi Folks,

I want to serialise Money types with Type Info, so that I can properly use it in serialised collections. In order to achieve this, I use Jackson DefaultTyping for polymorphic serialisation. Otherwise, type information will get lost when I serialise a Collection.

This is my (simplified) scenario:

public class ParentDomainObject {
  private Long id;
  private Set<ChildDomainObject> children;
}

public class ChildDomainObject {
  private Long id;
  private MonetaryAmount cost;
}

public class SomeHandler {
  public void serialiseMyDomainObjects() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new MoneyModule());
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE);

    ParentDomainObject o1 = new ParentDomainObject();
    // add some child objects

    ParentDomainObject o2 = new ParentDomainObject();
    // add some child objects

    mapper.writeValueAsString(Sets.asSet(o1, o2));
  }
}

When I try to run this, I get the following Exception:

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Type id handling not implemented for type org.javamoney.moneta.Money (by serializer of type org.zalando.jackson.datatype.money.MonetaryAmountSerializer)

I hope you get the point. Is this simply not supported (at the moment) or is there any way to work around this?

Cheers,
Stefan

@whiskeysierra
Copy link
Collaborator

What's your goal? Do you want to preserve the type information, i.e. which implementation of MonetaryAmount it was when serializing?

@stefanzilske
Copy link
Author

Yes, exactly.

If I don't use the DefaultTyping, Jackson will not be able to deserialise the DomainObjects inside the collection again, as it has no type information. DefaultTyping add the necessary type information, but it does not work with Money types.

@whiskeysierra
Copy link
Collaborator

@stefanzilske Can you take a look at #47?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants