On Sep 14, 2010, at 11:54 PM, JamesKPublic wrote:
> I'm trying to use a custom JSON serializer for my class, but for
> some reason, the framework is not invoking the serializer. I've set
> a breakpoint to confirm that it's not getting called, and the output
> looks like the default formatting.
> Is this bit of wiring that I forgot to perform?
How did you register your MessageBodyWriter implementation for the
type EmailMessage?
Paul.
> Code below.
>
> THanks
>
> James
>
>
>
> @XmlRootElement
> public class EmailMessage {
> private Map<String, String[]> headers;
>
> @JsonSerialize(using=NVMapJsonSerializer.class)
> public Map<String, String[]> getHeaders() {
> return headers;
> }
> @JsonDeserialize(using=NVMapJsonDeserializer.class)
> public void setHeaders(Map<String, String[]> headers) {
> this.headers = headers;
> }
> }
>
> @Path("email")
> @Produces("application/json")
> public class EmailResource {
> @GET
> @Produces("application/json")
> public EmailMessage getMessage() throws Exception {
>
> HashMap<String, String[]> headers = new HashMap<String,
> String[]>(5);
> EmailMessage emailMessage = new EmailMessage();
> headers.put("TO", new String[] {"steve_at_test.com","everbody_at_test.com
> "});
> headers.put("FROM", new String[] {"james_at_test.com"});
> emailMessage.setHeaders(headers);
>
> return emailMessage;
> }
> }