Tag: jackson

泽西+jackson反序列化失败与日期对象

我正在使用jersey和jackson来开发我的REST API,并且在反序列化日期字符串时遇到问题。 我在泽西岛注册了一个提供者类: @Provider public class MyJsonProvider extends JacksonJsonProvider { public static final String DATE_FORMAT = “yyyy-MM-dd HH:mm:ss”; @Override public void writeTo(Object value, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { ObjectMapper mapper = locateMapper(type, mediaType); // Enable human readable date format SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); […]

Maven – 无法下载fastxml.jackson

在maven pom.xml中: com.fasterxml.jackson.core jackson-core 2.5.0 bundle com.fasterxml.jackson.core jackson-databind 2.5.0 bundle com.fasterxml.jackson.core jackson-annotations 2.5.0 bundle maven无法下载这3个库,但可以成功下载所有其他库。 我在不同网络环境下的2台计算机上试过这个,结果是一样的。 eclipse中的错误消息: Missing artifact com.fasterxml.jackson.core:jackson-core:bundle:2.5.0 关于如何检查原因的任何建议?

创建一个JsonProcessingException

我正在尝试创建一个由模拟对象抛出的JsonProcessingException。 when(mapper.writeValueAsString(any(Object.class))).thenThrow(new JsonProcessingException(“Error”)); 但是我无法创建JsonProcessingException对象,因为所有构造函数都受到保护。 我该如何解决这个问题?

自定义Jackson HttpMessageConverter不再适用于Spring 4.2

我正在将一个应用程序从Spring Platform 1.1.3.RELEASE更新到2.0.1.RELEASE,它将Spring Framework版本从4.1.7升级到4.2.4,将Jackson从2.4.6升级到2.6.4。 Spring或Jackson处理自定义HttpMessageConverter实现似乎没有任何重大变化,但我的自定义JSON序列化未能发生,我无法确定原因。 以下在Spring Platform版本中可以正常工作: 模型 @JsonFilter(“fieldFilter”) public class MyModel { /*model fields and methods*/ } 模型包装 public class ResponseEnvelope { private Set fieldSet; private Set exclude; private Object entity; public ResponseEnvelope(Object entity) { this.entity = entity; } public ResponseEnvelope(Object entity, Set fieldSet, Set exclude) { this.fieldSet = fieldSet; this.exclude = exclude; this.entity […]

由于java.lang.NoClassDefFoundError无法运行代码:com / fasterxml / jackson / annotation / JsonMerge

我在Intellij Idea 2018社区版中有一些测试代码,它有多个pom文件。 当我运行任何testng注释测试时,我收到一条错误,上面写着“没有找到测试”。 看起来问题是由于exception堆栈跟踪的这一部分: java.lang.NoClassDefFoundError:com / fasterxml / jackson / annotation / JsonMerge 我搜索了一个解决方案并找到了这个 – https://github.com/FasterXML/jackson-annotations/issues/119和这个https://stackoverflow.com/a/46406070 。 当我们在项目中没有相同版本的这些jar时,看起来会出现此问题。 1)jackson-core(2.8.8) 2)jackson-databind(2.9.2) 3)jackson-annotations(2.8.5) 如您所见,我对所有jar子没有相同的版本。 我查看了项目中的所有poms,并没有找到任何添加所有这些依赖项的地方。 我希望只在那里设置版本号。 我应该简单地在父pom文件中添加所有依赖项还是做其他事情? 如何在不损害项目的情况下解决此问题? 我怎么知道为什么这些jar子的版本不一样?

jackson没有逃脱JSON中的引用

我正在尝试将json放在java中的javascript文件中,但是当我将json写入字符串时,该字符串似乎不是javascript的有效json; 它缺少一些逃脱。 (这发生在json中的一个字符串中,我将其格式化为人造json。) 例如,这将是我的javascript文件中的有效json: { “message”: “the following books failed: [{\”book\”: \”The Horse and his Boy\”,\”author\”: \”CS Lewis\”}, {\”book\”: \”The Left Hand of Darkness\”,\”author\”: \”Ursula K. le Guin\”}, ]” } 不过,我得到的是双引号未被转义的地方: { “message”: “The following books failed: [{“book”: “The Horse and his Boy”,”author”: “CS Lewis”}, {“book”: “The Left Hand of Darkness”,”author”: “Ursula K. le Guin”}, […]

在Jackson ObjectMapper上配置缩进间距的最简单方法是什么?

我真的在努力解决这个问题时所感受到的复杂程度。 正如标题所说: 使用4空间PrettyPrinter创建Jackson ObjectMapper的简单方法是什么? 加分点:如何修改现有的 ObjectMapper以使其打印4个空格? 通过我的研究,我发现最简单的方法是启用漂亮的打印通常是在mapper上设置INDENT_OUTPUT : objectMapper.enable(SerializationFeature.INDENT_OUTPUT); 但是,这只启用DefaultPrettyPrinter ,它有2个缩进空格。 我想4.为了做到这一点,我似乎必须构建自己的ObjectMapper ,为JsonFactory提供一个JsonGenerator ,它有一个4个空格的PrettyPrinter 。 对于在其他平台上如此简单的东西来说,这太过激烈了。 请告诉我有一个更简单的方法。

如何使用jackson库将pojos附加到json文件中

我是jackson库的新手。我有定期在json文件中写入的数据。我所经历的所有当前教程都覆盖了该文件。

Hibernate用户和朋友JsonReference

我有两个表:Users和User_Friend用于显示与添加字段的关系。 CREATE TABLE public.users ( uuid VARCHAR(36) PRIMARY KEY NOT NULL, username VARCHAR(45) UNIQUE NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255), middle_name VARCHAR(255) ); CREATE TABLE public.user_friends ( uuid VARCHAR(36) PRIMARY KEY, user_uuid VARCHAR(36) REFERENCES public.users (uuid) NOT NULL, friend_uuid VARCHAR(36) REFERENCES public.users (uuid) NOT NULL, friendAddDate TIMESTAMP NOT NULL, friendTypeId INT NOT NULL, […]

如何使用Jackson或任何其他api反序列化对象数组?

我有一个模型定义,我需要映射jsonArray。模型如下: @JsonPropertyOrder({ “Command”, “Created”, “Id”, “Image”, “Labels”, “Names”, “Ports”, “Status” }) public class Container { @JsonProperty(“Command”) private String Command; @JsonProperty(“Created”) private long Created; @JsonProperty(“Id”) private String Id; @JsonProperty(“Image”) private String Image; @JsonProperty(“Labels”) private List Labels; @JsonProperty(“Names”) private List Names = new ArrayList(); @JsonProperty(“Ports”) private List Ports = new ArrayList(); @JsonProperty(“Status”) private String Status; //Getters and […]