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

Register a custom EnumSerializer to overwrite the default EnumSerializer #227

Closed
gembin opened this issue May 20, 2013 · 10 comments
Closed

Comments

@gembin
Copy link

gembin commented May 20, 2013

Create a custom CustomEnumSerializer, and add it to a SimpleModule as following:

public class CustomEnumSerializer extends StdScalarSerializer{
//... custom code here
}

public class MySimpleModule extends SimpleModule{
public void setupModule(SetupContext context) {
addSerializer(Enum.class,new CustomEnumSerializer());
}
}
and finally objectMapper.registerModule(new MySimpleModule());

But, currently, the CustomEnumSerializer dose not overwrite the default one.

@ceefour
Copy link

ceefour commented May 24, 2013

Thank you !!! :-) +1

@cowtowncoder
Copy link
Member

First part of implementation; serializer registration works.

cowtowncoder added a commit that referenced this issue Jun 7, 2013
@cowtowncoder
Copy link
Member

Completed implementation; will be included in 2.3.0 when it is out (which will take a while, as dev only started).

@ceefour
Copy link

ceefour commented Jun 7, 2013

Awesome! Thank you Tatu @cowtowncoder ! :)

@cowtowncoder
Copy link
Member

No problem; thank you for the idea!

@gembin
Copy link
Author

gembin commented Jun 16, 2013

Thank you @cowtowncoder !

@maxkremer
Copy link

I could really use this functionality but can't seem to figure out how. Is there any documentation or example code anywhere?

@cowtowncoder
Copy link
Member

@maxkremer Does SimpleModule registration not work for you then? It works just like any other custom serializer.

@maxkremer
Copy link

@cowtowncoder yes it does. Sorry for the dumb question. Looking at the test code helped me to understand how this work. Thanks

@cowtowncoder
Copy link
Member

@maxkremer no problem; glad you figured it out. Documentation is not as well organized as it should be, so I can understand it not being obvious.

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

4 participants