Jackson-Json串首字母大写无法识别

Jackson-Json串首字母大写无法识别

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.tgw360.common.json.JSONUtils;
import com.tgw360.entity.push.LiveMsgPush;
import org.springframework.cloud.cloudfoundry.com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.cloud.cloudfoundry.com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cloud.cloudfoundry.com.fasterxml.jackson.databind.SerializationFeature;

import java.io.IOException;

public class MyTestMain {

    public static void main(String[] args) {
        try{
            String jsonStr = "{\"IsAudit\":0,\"IsPublic\":1,\"MsgContent\":{\"Content\":\"rgsdfg\",\"ExContent\":[],\"MessageID\":7371,\"MessageType\":1,\"PublishType\":1,\"PublisherHeadAddress\":\"/src/image/chat/img/2018125141747143.jpg\",\"PublisherID\":13743,\"PublisherName\":\"张三\",\"SendTime\":20190220093755,\"TopicID\":7230,\"isReply\":0},\"ServiceHeadAddress\":\"/src/image/chat/img/2018125141747143.jpg\",\"ServiceID\":13743,\"ServiceName\":\"张三\",\"TopicID\":7230,\"UserType\":2,\"isExpiredVip\":0,\"isOpenVip\":0,\"isReply\":0,\"onlyVipShow\":0,\"publishHeadAddress\":\"/src/image/chat/img/2018125141747143.jpg\",\"publishUserID\":13743,\"publishUserName\":\"张三\",\"toUserId\":0,\"type\":5,\"vipLevel\":0}";
            ObjectMapper objectMapper = new ObjectMapper();
            LiveMsgPush message = objectMapper.readValue(jsonStr, LiveMsgPush.class);
            System.out.println(JSONUtils.toJSONString(message));
        }catch(Exception e){
            e.printStackTrace();
        }

//        fun();
    }

    public static void fun(){
        ObjectMapper mapper = new ObjectMapper();
        String jsonString = "{\"Name\":\"Mahesh\", \"age\":21}";

        //map json to student
        try {
            Student student = mapper.readValue(jsonString, Student.class);
            System.out.println(student);
            mapper.enable(SerializationFeature.INDENT_OUTPUT);
            //把对象转成json string类型的
            jsonString = mapper.writeValueAsString(student);
            System.out.println(jsonString);

        } catch (JsonParseException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

class Student {
    @JsonProperty(value = "Name")
    private String Name;

    private int age;

    public Student(){}

    public String getName() {
        return Name;
    }
    public void setName(String name) {
        this.Name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}

你可能感兴趣的:(java-json)