无法使用camel编组格式化LocalDate对象
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法使用camel编组格式化LocalDate对象相关的知识,希望对你有一定的参考价值。
我正在使用驼峰路由将用户对象保存到文件,同时保存我正在使用camel marshaling选项将用户对象转换为json。虽然编组它是以下列格式保存日期对象
"birthDate":{"year":2018,"month":"FEBRUARY","era":"CE","dayOfMonth":20,"dayOfWeek":"TUESDAY","dayOfYear":51,"leapYear":false,"monthValue":2,"chronology":{"id":"ISO","calendarType":"iso8601"}}
想要的格式是
"birthDate":"20-feb-2018"
这是我的POJO
public class User implements Serializable{
private String id;
private String fName;
private String lName;
private String email;
private Integer pinCode;
@JsonFormat(pattern="dd-MMM-yyyy")
private LocalDate birthDate;
private Boolean isActive;
}
路由网址是
from("direct:saveUserJson").marshal().json(JsonLibrary.Jackson,User.class).to("file:"+filePath+"?fileName=${exchangeProperty.fileName}");
和pom.xml我在使用版本2.20.1的camel-jackson-starter和camel-spring-boot-starter
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.igtb</groupId>
<artifactId>assignment1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>assignment1</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.20.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>2.20.1</version>
</dependency>
</dependencies>
</project>
答案
不确定,但是当您将形状String
添加到注释时,它可能会起作用:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MMM-yyyy")
以上是关于无法使用camel编组格式化LocalDate对象的主要内容,如果未能解决你的问题,请参考以下文章
在camel编组期间出现InvalidPayloadException
如何将 LocalDate 对象格式化为 MM/dd/yyyy 并保持格式不变