Tag: jackson

jackson和genericstypes的参考

我想使用jacksonjson库的一般方法,如下所示: public MyRequest<T> tester(){ TypeReference<MyWrapper<T>> typeRef = new TypeReference<MyWrapper<T>>(); MyWrapper<T> requestWrapper = (MyWrapper<T>) JsonConverter.fromJson(jsonRequest, typeRef); return requestWrapper.getRequest(); } public class MyWrapper<T> { private MyRequest<T> request; public MyRequest<T> getRequest() { return request; } public void setRequest(MyRequest<T> request) { this.request = request; } } public class MyRequest{ private List<T> myobjects; public void setMyObjects(List<T> ets) { this.myobjects = […]

Springconfiguration@ResponseBody JSON格式

想象一下我在Spring 3 @Controller中有这个注解的方法 @RequestMapping("") public @ResponseBody MyObject index(@RequestBody OtherObject obj) { MyObject result = …; return result; } 但是我需要configuration输出json格式,就像我在做: ObjectMapper om = new ObjectMapper(); om.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true); om.getSerializationConfig() .setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT); om.getSerializationConfig() .set(SerializationConfig.Feature.INDENT_OUTPUT, false); 有什么办法来configuration这种行为? 我发现了一些相关的问题,但我不确定如何使它们适应我的具体情况: spring前缀与响应者 谁在S​​pring MVC中设置响应内容types(@ResponseBody) 谢谢 !

jackson与JSON:无法识别的领域,没有标记为可忽略的

我需要将某个JSONstring转换为Java对象。 我正在使用Jackson进行JSON处理。 我无法控制input的JSON(我从Web服务读取)。 这是我的inputJSON: {"wrapper":[{"id":"13","name":"Fred"}]} 这是一个简化的用例: private void tryReading() { String jsonStr = "{\"wrapper\"\:[{\"id\":\"13\",\"name\":\"Fred\"}]}"; ObjectMapper mapper = new ObjectMapper(); Wrapper wrapper = null; try { wrapper = mapper.readValue(jsonStr , Wrapper.class); } catch (Exception e) { e.printStackTrace(); } System.out.println("wrapper = " + wrapper); } 我的实体类是: public Class Student { private String name; private String id; //getters […]

什么时候使用@JsonProperty属性,它用于什么?

这个bean'状态': public class State { private boolean isSet; @JsonProperty("isSet") public boolean isSet() { return isSet; } @JsonProperty("isSet") public void setSet(boolean isSet) { this.isSet = isSet; } } 通过使用ajax'成功'callback的电线发送: success : function(response) { if(response.State.isSet){ alert('success called successfully) } 这里需要注解@JsonProperty吗? 使用它的优点是什么? 我想我可以删除这个注释而不会造成任何副作用。 在https://github.com/FasterXML/jackson-annotations/wiki/Jackson-Annotations阅读关于这个annotion我不知道这是什么时候需要使用?

如何使用Jackson JSON将JSONstring转换为Map <String,String>

这是我第一次尝试做一些有用的Java ..我试图做这样的事情,但它不起作用: Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap = JacksonUtils.fromJSON(properties, Map.class); 但IDE说:'未检查的分配Map to Map<String,String> ' 什么是正确的方法来做到这一点? 我只使用jackson,因为这是项目中已有的东西,有没有Java转换到/从JSON的本地Java方式? 在PHP中,我只是简单的json_decode($str) ,我会得到一个数组。 我在这里需要基本相同的东西。 谢谢!

如何指定jackson只使用字段 – 最好全球

默认的jackon行为似乎使用两个属性(getters和setter)和字段序列化和反序列化为json。 我想使用这些字段作为序列化configuration的规范来源,因此不希望jackson看到属性。 我可以在个人课程的基础上加注释: @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) 但我不想把这个放在每一个class上 是否有可能在全球进行configuration? 像添加一些到物体映射?

如何将Joda DateTime与Jackson JSON处理器序列化?

我如何让jackson根据一个简单的模式(如“dd-MM-yyyy”)序列化我的Joda DateTime对象? 我试过了: @JsonSerialize(using=DateTimeSerializer.class) private final DateTime date; 我也试过: ObjectMapper mapper = new ObjectMapper() .getSerializationConfig() .setDateFormat(df); 谢谢!

如何在Wildfly中configurationJackson?

我有一个会话Bean与以下方法: @POST @Consumes("application/x-www-form-urlencoded") @Path("/calculate") @Produces("application/json") public CalculationResult calculate(@FormParam("childProfile") String childProfile, @FormParam("parentProfile") String parentProfile) { … } 返回的CalculationResult不能映射到JSON并发生以下exception: Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.test.UniqueName and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)… 我如何在Wildfly中configurationJackson及其SerializationFeature ?

用Jackson将Java对象转换成JSON

我想我的JSON看起来像这样: { "information": [{ "timestamp": "xxxx", "feature": "xxxx", "ean": 1234, "data": "xxxx" }, { "timestamp": "yyy", "feature": "yyy", "ean": 12345, "data": "yyy" }] } 目前代码: import java.util.List; public class ValueData { private List<ValueItems> information; public ValueData(){ } public List<ValueItems> getInformation() { return information; } public void setInformation(List<ValueItems> information) { this.information = information; } @Override public […]

我如何使用Jackson的自定义串行器?

我有两个我想用JSON序列化成JSON的Java类: public class User { public final int id; public final String name; public User(int id, String name) { this.id = id; this.name = name; } } public class Item { public final int id; public final String itemNr; public final User createdBy; public Item(int id, String itemNr, User createdBy) { this.id = id; this.itemNr […]