@JSONField它在春季启动时不起作用



我对pointX和pointY使用@JSONField注释,我想将pointX更改为point_x!我想像point_x一样展示pointX!但它没有起作用!它总是点X和点Y!但其他领域是可以的!

我的java豆是这样的!

@Data
public class PointListOutput {

@JSONField(name = "latest_area_point_list")
private List<Point> latestAreaPointList;
@Data
public static class Point {
@JSONField(name = "point_x")
private Float pointX;
@JSONField(name = "point_y")
private Float pointY;
}
}

我的配置

@Override
protected void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
// create FastJson converter
final FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
final List<MediaType> supportedMediaTypes = new ArrayList<>();
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
converter.setSupportedMediaTypes(supportedMediaTypes);
// create configuration class
final FastJsonConfig config = new FastJsonConfig();
// update filter of response
config.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue);
converter.setFastJsonConfig(config);
converters.add(new ByteArrayHttpMessageConverter());
converters.add(converter);
}

这是我的http响应,正如您所看到的,pointX就是pointX!不是point_x!

{
"code": 1,
"message": "Success",
"data": [
{
"latest_area_point_list": [
{
"pointX": 1.1,
"pointY": 1.1
},
{
"pointX": null,
"pointY": 1.1
}
]
}
]
}

我解决了这个问题,因为org.springframework.beans.BeanUtils.copyProperties
我使用org.springframework.beans.BeanUtils.copyProperties将DAO java bean更改为View java bean
My Dao java bean

@Data
@DynamoDBTable(tableName = "xxxx")
public class PointPojo {
@DynamoDBAttribute(attributeName = "latest_area_point_list")
private List<Point> latestAreaPointList;
@Data
@DynamoDBDocument
public static class Point {
@DynamoDBAttribute(attributeName = "point_x")
private Float pointX;
@DynamoDBAttribute(attributeName = "point_y")
private Float pointY;
}
}

PointPojo没有@JSONField(name = "point_x")
copyProperties之后,Point不是PointListOutput$Point,它是PointPojo@Point,它没有@JSONField(name = "point_x")
所以这是根本原因!

我用orika代替org.springframework.beans.BeanUtils.copyProperties,太完美了

相关内容

  • 没有找到相关文章

最新更新