Applicationcontext.xml
1 <Beanclass= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 2 < Propertyname= "Messageconverters"> 3 <List> 4 <Beanclass= "Org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 5 < Propertyname= "Supportedmediatypes"> 6 <List> 7 <value>Text/plain;charset=utf-8</value> 8 <value>Application/json;charset=utf-8</value> 9 </List> Ten </ Property> One < Propertyname= "Objectmapper"> A <Beanclass= "Com.charmyin.cmstudio.common.utils.ObjectMappingCustomer"></Bean> - </ Property> - </Bean> the </List> - </ Property> - </Bean>
I tried it here, too.
<Bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter "> ... </bean>
Objectmappingcustomer.java
1 Packagecom.charmyin.cmstudio.common.utils;2 3 4 Importjava.io.IOException;5 6 ImportCom.fasterxml.jackson.databind.JsonSerializer;7 ImportCom.fasterxml.jackson.databind.ObjectMapper;8 ImportCom.fasterxml.jackson.core.JsonGenerator;9 ImportCom.fasterxml.jackson.core.JsonParser; Ten Importcom.fasterxml.jackson.core.JsonProcessingException; One ImportCom.fasterxml.jackson.databind.SerializerProvider; A - Public classObjectmappingcustomerextendsObjectmapper - the { - - /** - * + */ - Private Static Final LongSerialversionuid = 1L; + A at - PublicObjectmappingcustomer () - - { - // - Super(); in - //allow single quotation marks to + This. Configure (JsonParser.Feature.ALLOW_SINGLE_QUOTES,true); - the //fields and values are quoted * $ This. Configure (JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES,true); Panax Notoginseng - //numbers are also quoted the + This. Configure (JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS,true); A the This. Configure (JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS,true); + // - // //null processing is an empty string $ // $Serializerprovider sp = (serializerprovider) This. Getserializerprovider (); - -Sp.setnullvalueserializer (NewJsonserializer<object>(){ the - Wuyi the @Override - Wu Public voidSerialize (Object value, Jsongenerator JG, - AboutSerializerprovider sp)throwsIOException, $ - jsonprocessingexception { - -Jg.writestring (""); A + } the - $ the }); the // the // the // - } in the}
JSON for output
{ "rows": [ { null, "praId": " BFFA397B245849909A9C2AF4E74E007D19A1E6CB ", " Creatorid ": 248, " creatorname ":" Stu123 ", null } ]}
Spring MVC JSON problem