[英]Java Spring controller response not being converted to JSON
I have the following method:我有以下方法:
@RequestMapping(value = "/products/{productId}", method = RequestMethod.GET)
@ResponseBody
public ProductDTO getProductById()...{
//return populated ProductDTO.
}
ProductDTO have the following structure: ProductDTO具有以下结构:
public class ProductDTO implement Serializable{
String id;
Double price;
Color color;
}
-----
public class Color implements Serializable {
String name;
String RgbValue;
}
The problem here is that the Color attribute isn't being marshalled: The JSON that I get in the response is the following:这里的问题是 Color 属性没有被编组:我在响应中得到的 JSON 如下:
{
"id" : "V6 Motor"
"price" : "616$"
"color" : "com.test.src.data.Color@16b7656b"
}
Why the Color isn't being marshalled ?为什么颜色没有被编组?
尝试覆盖 Color 的 toString 方法,因为我认为 Spring 试图将其视为字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.