简体   繁体   中英

MessagePack Java serializing as array

Is it accepted behaviour that MessagePack official implementation in Java serializes public fields as Arrays?

In what universe is this "like 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.

Node JS can easily unpack it, to

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

Which means that MessagePack is nothing like JSON, because it parses Java objects as arrays and then only repopulates them alphabetically!

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)

Judging from my MessagePack experience, it usually treats objects as MessagePack maps.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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