SPRINGMVC Back to JSON debugging

Source: Internet
Author: User

spring-web-5.0.6.release.jar!/org/springframework/web/method/support/ Handlermethodreturnvaluehandlercomposite.class

public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {        HandlerMethodReturnValueHandler handler = this.selectHandler(returnValue, returnType);        if (handler == null) {            throw new IllegalArgumentException("Unknown return value type: " + returnType.getParameterType().getName());        } else {            handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest);        }    }

spring-webmvc-5.0.6.release.jar!/org/springframework/web/servlet/mvc/method/annotation/ Requestresponsebodymethodprocessor.class

    public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException {        mavContainer.setRequestHandled(true);        ServletServerHttpRequest inputMessage = this.createInputMessage(webRequest);        ServletServerHttpResponse outputMessage = this.createOutputMessage(webRequest);        this.writeWithMessageConverters(returnValue, returnType, inputMessage, outputMessage);    }

spring-webmvc-5.0.6.release.jar!/org/springframework/web/servlet/mvc/method/annotation/ Abstractmessageconvertermethodprocessor.class

protected <T> void Writewithmessageconverters (@Nullable T value, Methodparameter returntype, Servletserverhttprequest inputmessage, Servletserverhttpresponse outputmessage) throws IOException,        Httpmediatypenotacceptableexception, httpmessagenotwritableexception {Object outputvalue;        Class ValueType;        Object Declaredtype;            if (value instanceof charsequence) {outputvalue = Value.tostring ();            ValueType = String.class;        Declaredtype = String.class;            } else {outputvalue = value;            ValueType = This.getreturnvaluetype (value, returntype);        Declaredtype = This.getgenerictype (returntype); } if (This.isresourcetype (value, ReturnType)) {outputmessage.getheaders (). Set ("Accept-ranges", "bytes")            ; if (value! = null && inputmessage.getheaders (). GetFirst ("Range")! = null) {Resource Resource = (Re                source) value;               try {     list

Serializes the object.
Jackson-databind-2.9.5-sources.jar!/com/fasterxml/jackson/databind/ser/beanserializer.java

public final void serialize(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException { if (_objectIdWriter != null) { gen.setCurrentValue(bean); // [databind#631] _serializeWithObjectId(bean, gen, provider, true); return; } gen.writeStartObject(bean); if (_propertyFilterId != null) { serializeFieldsFiltered(bean, gen, provider); } else { serializeFields(bean, gen, provider); } gen.writeEndObject(); }

The field of the serialized object.
Jackson-databind-2.9.5-sources.jar!/com/fasterxml/jackson/databind/ser/std/beanserializerbase.java

protected void Serializefields (Object bean, Jsongenerator gen, Serializerprovider provider) throws IOException { Final beanpropertywriter[] props; if (_filteredprops! = null && provider.getactiveview () = null) {props = _filteredprops; } else {props = _props; } int i = 0; try {for (final int len = props.length; i < Len; ++i) {Beanpropertywriter prop = Props[i]; if (prop! = null) {//Can has nulls in filtered list Prop.serializeasfield (Bean, Gen, Provider); }} if (_anygetterwriter! = null) {_anygetterwriter.getandserialize (bean, Gen, provi der); }} catch (Exception e) {String name = (i = = props.length)? "[Anysetter]": props[i].getname (); Wrapandthrow (provider, E, Bean, name); } catch (Stackoverflowerror e) {//04-sep-2009, TAtu:dealing with the tricky, since we don't have many//stacks frames to spare ... just one or both; Can ' t make many calls. 10-DEC-2015, Tatu:and due to above, avoid ' from ' method, call ctor directly://jsonmappingexception MapE = Jsonmappingexception.from (Gen, "Infinite recursion (Stackoverflowerror)", e); Jsonmappingexception MapE = new Jsonmappingexception (gen, "Infinite recursion (Stackoverflowerror)", e); String name = (i = = props.length)? "[Anysetter]": props[i].getname (); Mape.prependpath (New Jsonmappingexception.reference (bean, name)); Throw MapE; } }

Serialize a field
Jackson-databind-2.9.5-sources.jar!/com/fasterxml/jackson/databind/ser/beanpropertywriter.java

public void Serializeasfield (Object bean, Jsongenerator gen, Serializerprovider Prov) throws Exception { inlined ' Get () ' final Object value = (_accessormethod = = null)? _field.get (Bean): _accessormethod.invoke (Bean, (object[]) null); Null handling is bit different, check that first if (value = = null) {if (_nullserializer! = null) { Gen.writefieldname (_name); _nullserializer.serialize (null, gen, Prov); } return; }/Then find serializer-use jsonserializer<object> ser = _serializer; if (Ser = = null) {class<?> CLS = Value.getclass (); Propertyserializermap m = _dynamicserializers; Ser = m.serializerfor (CLS); if (Ser = = null) {Ser = _findandadddynamic (M, CLS, Prov); }}//And then see if we must suppress certain values (default, empty) if (_suppressablevalue! = null) {if (Marker_for_empty = = _suppressablevalue) {if (ser.ise Mpty (Prov, value)) {return; }} else if (_suppressablevalue.equals (value)) {return; }}//For non-nulls:simple check for direct cycles if (value = = Bean) {//three choices : Exception; handled by call; or pass-through if (_handleselfreference (Bean, gen, Prov, Ser)) {return; }} gen.writefieldname (_name); if (_typeserializer = = null) {ser.serialize (value, gen, Prov); } else {Ser.serializewithtype (value, gen, Prov, _typeserializer); } }

Springmvc back to JSON debugging

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.