简体   繁体   English

MessagePack Java序列化为数组

[英]MessagePack Java serializing as array

Is it accepted behaviour that MessagePack official implementation in Java serializes public fields as Arrays? Java中的MessagePack官方实现将公共字段序列化为Array是公认的行为吗?

In what universe is this "like JSON"? 这个“像JSON”在什么宇宙中?

My case: I have a simple class like so: 我的情况:我有一个像这样的简单班级:

@Message
public class MySuperClass(){
    public int mySuperID; // let's say 4
    public byte[] mySuperData; // let's say nothing
    public String mySuperType; // let's say null
    public String mySuperExtra; // let's say HI!

    public MySuperClass(){}

    // other constructors
}

And i'm simply serializing with 而且我只是与序列化

MessagePack msgpack = new MessagePack();
msgpack.write(mySuperInstance);

And sending that to a distant server written in NodeJS. 并将其发送到用NodeJS编写的远程服务器。

Node JS can easily unpack it, to Node JS可以轻松解压缩它,以

['HI!', �, 4, null]

Which means that MessagePack is nothing like JSON, because it parses Java objects as arrays and then only repopulates them alphabetically! 这意味着MessagePack与JSON完全不同,因为它会将Java对象解析为数组,然后仅按字母顺序重新填充它们!

Does anyone have a solution that does not include mapping every object I have? 是否有人解决方案不包括映射我拥有的每个对象? (Also HashMap is not unpackable by Node, which means that messagePack is not cross-platform ,thus, repeating, noting like JSON) (HashMap也不能由Node解包,这意味着messagePack不是跨平台的,因此,重复进行,就像JSON一样)

Judging from my MessagePack experience, it usually treats objects as MessagePack maps. 从我对MessagePack的经验来看,它通常将对象视为MessagePack映射。

It doesn't use any language specific constructs so it is cross - platform. 它不使用任何语言特定的构造,因此它是跨平台的。

I think you may be having issues because of the library you are using. 我认为您可能由于使用的库而遇到问题。 You should consider the official one. 您应该考虑正式的。 You can read more about it here . 您可以在此处了解更多信息。 It is basically an extension for Jackson that let's serialise and deserialise Java objects directly to / from MessagePack and was working (at least when I had to use it). 基本上,这是Jackson的扩展,让我们直接将Java对象序列化和反序列化到MessagePack或从MessagePack反序列化,并且可以正常工作(至少在我必须使用它的时候)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM