Stomp and Jackson

Source: Internet
Author: User
Tags stomp

The class that reads the STOMP message is in Stompdecoder, Org.springframework.messaging.simp.stomp.StompDecoder.

Jackson turned the JSON object into the following steps:

1. Resolveargument in Org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite class ( Methodparameter parameter, message<?> Message) method, returns an object

2. Resolveargument in Org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver class ( Methodparameter parameter, message<?> message) method, Object target = this.converter.fromMessage (message, Targetclass);

3. Call the frommessage of the Org.springframework.messaging.converter.CompositeMessageConverter class (Message<?> Message, Class<?> Targetclass) method, traverse all converters in this class, find the appropriate result and return.

4. Call Frommessage in the Org.springframework.messaging.converter.AbstractMessageConverter class (Message<?> Message, Class<?> targetclass) convertfrominternal (message, targetclass);

5, convertfrominternal (message, targetclass); method is instantiated in Org.springframework.messaging.converter.MappingJackson2MessageConverter (PS: You can also use other convert, as long as spring supports it):

Public Object convertfrominternal (Message<? > Message, class< ?> Targetclass) {        Javatype javatype = This.objectMapper.constructType (targetclass);        Object payload = Message.getpayload ();//Here you can see the fetch message byte stream        try {            if (payload instanceof byte[]) {                return This.objectMapper.readValue ((byte[]) payload, javatype);//This is the core of the conversion            }            else {                return This.objectMapper.readValue (String) payload, javatype);}        }        catch (IOException ex) {            throw new messageconversionexception (message, "Could not read JSON:" + ex.getmessage (), ex) ;        }    }

6. Starting from here, call the Fasterxml.jackson package to bind the data.

By default, JSON is bound to map, and if there is an object, the map is converted to an object.

Stomp and Jackson

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.