Created
December 15, 2016 15:10
-
-
Save Anticom/6d773a4045e0559e4280bab68e358ab0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.anticom.model.opensearch; | |
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | |
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
import eu.anticom.serializer.ContactDeserializer; | |
import eu.anticom.serializer.ContactSerializer; | |
import javax.mail.internet.AddressException; | |
import javax.mail.internet.InternetAddress; | |
import java.io.UnsupportedEncodingException; | |
@JsonSerialize(using = ContactSerializer.class) | |
@JsonDeserialize(using = ContactDeserializer.class) | |
public class Contact extends InternetAddress { | |
public Contact() { | |
super(); | |
} | |
public Contact(String address) throws AddressException { | |
super(address); | |
} | |
public Contact(String address, boolean strict) throws AddressException { | |
super(address, strict); | |
} | |
public Contact(String address, String personal) throws UnsupportedEncodingException { | |
super(address, personal); | |
} | |
public Contact(String address, String personal, String charset) throws UnsupportedEncodingException { | |
super(address, personal, charset); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.anticom.serializer; | |
import com.fasterxml.jackson.core.JsonGenerator; | |
import com.fasterxml.jackson.databind.SerializerProvider; | |
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | |
import javax.mail.internet.InternetAddress; | |
import java.io.IOException; | |
public class ContactSerializer extends StdSerializer<InternetAddress> { | |
public ContactSerializer() { | |
this(null); | |
} | |
public ContactSerializer(Class<InternetAddress> t) { | |
super(t); | |
} | |
@Override | |
public void serialize(InternetAddress internetAddress, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | |
jsonGenerator.writeStartObject(); | |
jsonGenerator.writeStringField("foo", internetAddress.toString()); | |
jsonGenerator.writeEndObject(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- expected --> | |
<MyRootNode> | |
<Contact>[email protected]</Contact> | |
</MyRootNode> | |
<!-- actual --> | |
<MyRootNode> | |
<Contact> | |
<foo>[email protected]</foo> | |
</Contact> | |
</MyRootNode> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JacksonXmlRootElement(localName = "MyRootNode", namespace = NS) | |
public class MySchema { | |
public static final String NS = "http://a9.com/-/spec/opensearch/1.1/"; | |
@JacksonXmlProperty(localName = "Contact", namespace = NS) | |
private Contact contact; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment