उत्पन्न करता है मैंने स्प्रिंग के साथ एक शानदार वेब सेवा लागू की है। सेवा स्वीकृति शीर्षलेख के आधार पर एक्सएमएल या जेएसओएन में प्रतिक्रिया देती है।वसंत आरईएसटी | मैपिंग जैक्सन एचटीपी मैसेज कनवर्टर अवैध JSON
@Controller
@RequestMapping(value = "/entityService")
class RestfulEntityService {
@Resource
private EntityService entityService;
@ResponseBody
@RequestMapping(value = "/getAllEntities", method = RequestMethod.GET)
public List<Entity> getAllEntities() {
return entityService.getAllEntities();
}
}
XML प्रतिक्रिया, मान्य है तथापि, जब क्लाइंट अनुप्रयोग/json को स्वीकार करें हैडर सेट, प्रतिक्रिया है:
<bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"/>
<bean id="xmlMessageConverter"
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg ref="xstreamMarshaller"/>
<property name="supportedMediaTypes" value="application/xml"/>
</bean>
<bean id="jsonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="prefixJson" value="false"/>
<property name="supportedMediaTypes" value="application/json"/>
</bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="xmlMessageConverter"/>
<ref bean="jsonHttpMessageConverter"/>
</util:list>
</property>
</bean>
यहाँ मेरी नियंत्रक विधि है: यहाँ context.xml मानचित्रण है अवैध JSON।
[{"id":3,"attributes":[{"id":18,"attributeValue":null,"attributeName":"mobile","attributeType":"varchar(40)","entity":{"id":3,"attributes":[{"id":18,"attributeValue":null,"attributeName":"mobile","attributeType":"varchar(40)","entity":{"id":3,"attributes":[{"id":18,"attributeValue":null,"attributeName":"mobile","attributeType":"varchar(40)","entity":{"id":3,"attributes": ..... repeats for a while and then stops..
एक पूर्ण वैध और पूर्ण अमान्य प्रतिक्रिया पोस्ट करने के लायक हो सकता है –
अमान्य प्रतिक्रिया बहुत बड़ी है (इसलिए वैध प्रतिक्रिया है) क्योंकि इसे 100 इकाइयों की सूची क्रमबद्ध करना है। मैंने जो अमान्य प्रतिक्रिया पोस्ट की है वह सिर्फ सौ बार दोहराई जाती है और बंद हो जाती है .. – Sri
दिलचस्प बात यह है कि एक या दो इकाइयों के साथ एक छोटी सूची जेएसओएन में क्रमबद्ध हो जाती है .. – Sri