我正在我的gradle项目中使用com.fasterxml.jackson.core:jackson-annotations:2.6.0
。自从将com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.0
添加到我的项目构建文件后,我在运行gradle项目时遇到了这个异常。这里是我的错误的堆栈跟踪。
我在我的类中使用了未使用的@jsonformat
。但是我确实有JSONSerializer
和JSONDeserializer
注释,它们使用两个类来序列化和反序列化我的ZonedDateTime
到UTC格式的Json和从Json到Json的ZonedDateTime
。我是第一次做这个序列化和反序列化,所以请给出任何建议。
这是我的分级文件代码:
apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'jetty' apply plugin: 'maven' apply plugin: 'war'
ext { springVersion = "4.2.4.RELEASE" springSecurityVersion = "4.0.3.RELEASE" }
repositories { mavenLocal() mavenCentral()
/* maven {
url "http://repo.typesafe.com/typesafe/releases/"
} */ }
configurations.all { exclude group: "commons-logging", module: "commons-logging" exclude group: "log4j", module: "log4j" }
dependencies { compile 'org.slf4j:jcl-over-slf4j:1.7.12' compile 'ch.qos.logback:logback-classic:1.1.3' compile "org.springframework:spring-core:$springVersion" compile "org.springframework:spring-context:$springVersion"
compile ("org.springframework:spring-web:$springVersion"){
exclude group: "com.fasterxml.jackson.core" } compile ("org.springframework:spring-webmvc:$springVersion"){
exclude group: "com.fasterxml.jackson.core" } compile "org.springframework:spring-orm:$springVersion" compile "org.springframework.security:spring-security-web:$springSecurityVersion" compile "org.springframework.security:spring-security-config:$springSecurityVersion"
compile "org.aspectj:aspectjrt:1.7.4"
compile "org.hibernate:hibernate-core:4.3.6.Final" compile "org.hibernate:hibernate-entitymanager:4.3.6.Final" compile "javax.servlet:javax.servlet-api:3.1.0" compile "org.javassist:javassist:3.15.0-GA" compile "mysql:mysql-connector-java:5.1.31"
compile "org.hsqldb:hsqldb:2.3.2"
compile "commons-dbcp:commons-dbcp:1.2.2" compile "org.apache.commons:commons-lang3:3.4" compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.0' compile 'com.fasterxml.jackson.core:jackson-core:2.7.0' compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.7.0'
compile "net.sf.ehcache:ehcache-core:2.6.9" compile "org.hibernate:hibernate-ehcache:4.3.5.Final" compile "com.h2database:h2:1.4.177" compile "com.google.code.gson:gson:2.6.2"
testCompile ("junit:junit:4.12"){
exclude group: "org.hamcrest" } testCompile "org.springframework:spring-test:$springVersion" testCompile "org.easetech:easytest-core:1.4.0" testCompile "org.mockito:mockito-core:1.9.5" testCompile "org.hamcrest:hamcrest-all:1.3" testCompile "com.jayway.jsonpath:json-path:2.2.0" testCompile "com.jayway.jsonpath:json-path-assert:2.2.0"
testRuntime "org.hsqldb:hsqldb:2.3.2" }
检查您的项目依赖关系。您可能使用了不兼容的库版本。版本2.7的方法为empty(),版本2.6的方法为not。
http://fasterxml.html" target="_blank">github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/jsonformat.value.html
http://fasterxml.github.io/jackson-annotations/javadoc/2.7.0-rc1/com/fasterxml/jackson/annotation/jsonformat.value.html
请尝试升级到2.7版本。
我正在使用jackson库,我遇到了一种情况,我想在序列化/反序列化时使用对象映射器禁用@JsonFormat注释。 我的Api代码在第三方库中,所以我不能删除/添加任何注释,所以objectMapper是唯一的选择。 Api类别: 我的代码: 我希望这种转换成功发生。 目前我得到了:com.fasterxml.jackson.databind。JsonMappingException:格式无效:
我需要使用两个jackson 2对象映射器。两个映射器都使用同一组类。首先,我需要使用标准序列化。在第二个例子中,我想对所有类使用数组形状类型(请参见https://fasterxml.github.io/jackson-annotations/javadoc/2.2.0/com/fasterxml/jackson/annotation/JsonFormat.Shape.html#ARRAY).
后端实体类使用了@jsonformat注释,但在前端获取数据时24-hour和12hour中的时间格式似乎存在问题。例如,后端时间为2021-5-21 00:50,但发送到前端的时间变成了2021-5-21 12:50。是@jsonformat的属性设置有问题还是前端。
我想用特定的格式序列化POJO的某些日历字段。 我将添加一个格式为字符串的字段,因为它实际上是以24小时为单位表示一天,而不是一个特定的时间瞬间。但当我添加带有注释的新字段时: 我希望得到这样的JSON: 相反,我遇到了以下例外情况:
我试图使用Jackson注释来重新命名序列化过程中产生的一些json标签。所有注释都编译得很好,当我运行时,除了所有Jackson注释之外,Jackson序列化工作完全被忽略。即使像@jsonignore或@jsonproperty这样的基本命令对json响应也没有影响。构建路径中的库有: 下面是我需要序列化的一个类的代码示例: