在我的控制器类m使用ObjectMapper读取JSON数据,以及dat m将这些值存储在MyPojo类中之后,现在我想要打印POJO对象中存在的内容。如果我在做system.out.println(pojo);
它显示一些十六进制值。那么,我应该怎么做才能获得内容。将对象转换为字符串时出错
这是我的模型类:
package com.ge.health.model;
import java.util.Date;
public class JSONmodel {
private String message;
private String data;
private String datetime;
public String getDatetime() {
return datetime;
}
public void setDatetime(String datetime) {
this.datetime = datetime;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
这是我的主类Controller类
package com.ge.health.poc.controller;
import java.io.IOException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ge.health.model.JSONmodel;
@RestController
public class JSONSendController {
@RequestMapping(value="/messagejson",method= RequestMethod.POST)
@ResponseBody
public void helloService(@RequestBody(required = false) String input) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
JSONValidationClass validate=new JSONValidationClass();
System.out.println("Service Says 123 - " + input);
boolean retValue = validate.isValidJSON(input);
System.out.println("this is the value:"+retValue);
JSONmodel pojodata = mapper.readValue(input, JSONmodel.class);
System.out.println(pojodata);
System.out.println(pojodata.toString());
}
}
好了,你还没有覆盖'的toString()'的'JSONModel'类。你期望字符串表示是什么,以及你期望这样做的代码是什么? –
可能重复[如何打印我的Java对象而不会得到“SomeType @ 2f92e0f4”?](http://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-越来越 - sometype2f92e0f4) – Tom