1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | package com.ibm.jaxrs.sample.organization; import javax.ws.rs.Consumes; import javax.ws.rs.Produces; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; @Provider @Produces("text/xml") public class ContactInfoWriter implements MessageBodyWriter<ContactInfo> { public long getSize(T t, java.lang.Class<ContactInfo> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType) { ... } public boolean isWriteable(java.lang.Class<ContactInfo> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType) { return true; } public void writeTo(ContactInfo contactInfo, java.lang.Class<ContactInfo> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType, MultivaluedMap< java.lang.String, java.lang.Object> httpHeaders, java.io.OutputStream entityStream) { contactInfo.serialize(entityStream); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | package com.ibm.jaxrs.sample.organization; import javax.ws.rs.Consumes; import javax.ws.rs.Produces; import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.Provider; @Provider @Consumes("text/xml") public class ContactInfoReader implements MessageBodyReader<ContactInfo> { public boolean isReadable(java.lang.Class<ContactInfo> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType) { return true; } public ContactInfo readFrom(java.lang.Class<ContactInfo> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType, MultivaluedMap< java.lang.String,java.lang.String> httpHeaders, java.io.InputStream entityStream) { return ContactInfo.parse(entityStream); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |