小编Auf*_*Auf的帖子

哪一个更轻,JSON还是BSON?

我编写了将对象序列化为JSON和BSON的代码.根据我的输出,生成的BSON的大小比JSON大.这是预期的吗?

从我的代码Bson.class(使用杰克逊和bson4jackson)

private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private BsonFactory fac = new BsonFactory();

private ObjectMapper mapper = new ObjectMapper(fac);

public Bson(Object obj) throws JsonGenerationException,
        JsonMappingException, IOException {
    mapper.writeValue(baos, obj);
}

public int size() {
    return baos.size();
}

public String toString() {
    byte[] bytes = baos.toByteArray();
    return new String(bytes);
}
Run Code Online (Sandbox Code Playgroud)

从我的 Json.class

private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private ObjectMapper mapper = new ObjectMapper();

public Json(Object obj) throws JsonGenerationException,
        JsonMappingException, IOException {
    mapper.writeValue(baos, obj);
}
Run Code Online (Sandbox Code Playgroud)

(size()和 …

java json jackson bson

30
推荐指数
2
解决办法
6656
查看次数

@JsonRootName无法正常工作

这是我的FacilityDTO

@JsonRootName("Facility")
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name = "Facility", propOrder = { "id", "name", "totalQuantity" })
public class FacilityDTO implements Serializable {

private static final long serialVersionUID = 1L;

@XmlElement(required = true)
private String id;
@XmlElement(required = true)
private String name;
@XmlElement(required = true)
private double totalQuantity;

public FacilityDTO() {
}

public FacilityDTO(Facility facility) {
    this.name = facility.getName();
    this.totalQuantity = facility.getTotalQuantity();
    this.id = facility.getId();
}// getters setter
Run Code Online (Sandbox Code Playgroud)

这是我的留言机构作家

ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk7Module());
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
mapper.writeValue(out, …
Run Code Online (Sandbox Code Playgroud)

java json jaxb root jackson

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

jackson ×2

java ×2

json ×2

bson ×1

jaxb ×1

root ×1