Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception serializing double[][] #31

Closed
rsc1975 opened this issue Oct 14, 2016 · 2 comments
Closed

Exception serializing double[][] #31

rsc1975 opened this issue Oct 14, 2016 · 2 comments
Labels

Comments

@rsc1975
Copy link

rsc1975 commented Oct 14, 2016

To reproduce it (v. 2.8.3):

        ObjectMapper mapper = new ObjectMapper(new CBORFactory());
        byte[] cborBytes = mapper.writeValueAsBytes(new double[][]{ {1.2323132131} });

I suspect that the problem is in CBORGenerator the line 678, the call to _verifyValueWrite("") has been already performed in the parent method, line 601, but I'm not familiar with the code, maybe there is another cause.

    private final void _writeNumberNoCheck(double d) throws IOException {
        _verifyValueWrite("write number");
        _ensureRoomForOutput(11);

The exception log trace:

Exception in thread "main" com.fasterxml.jackson.core.JsonGenerationException: Array size mismatch: number of element encoded is not equal to reported array/map size.
    at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1897)
    at com.fasterxml.jackson.dataformat.cbor.CBORGenerator._failSizedArrayOrObject(CBORGenerator.java:1089)
    at com.fasterxml.jackson.dataformat.cbor.CBORGenerator._verifyValueWrite(CBORGenerator.java:1080)
    at com.fasterxml.jackson.dataformat.cbor.CBORGenerator._writeNumberNoCheck(CBORGenerator.java:678)
    at com.fasterxml.jackson.dataformat.cbor.CBORGenerator.writeArray(CBORGenerator.java:604)
    at com.fasterxml.jackson.databind.ser.std.StdArraySerializers$DoubleArraySerializer.serialize(StdArraySerializers.java:686)
    at com.fasterxml.jackson.databind.ser.std.StdArraySerializers$DoubleArraySerializer.serialize(StdArraySerializers.java:620)
    at com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer.serializeContents(ObjectArraySerializer.java:256)
    at com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer.serialize(ObjectArraySerializer.java:216)
    at com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer.serialize(ObjectArraySerializer.java:26)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
    at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672)
    at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:3072)

@cowtowncoder
Copy link
Member

Thank you for reporting this. writeArray() is a relatively recent addition which makes sense as otherwise this code path should be tested reasonably well.

@cowtowncoder cowtowncoder changed the title [cbor] Exception serializating double[][] Exception serializing double[][] Oct 15, 2016
@cowtowncoder
Copy link
Member

cowtowncoder commented Oct 15, 2016

Yes, you are right: there was an extra check (funny that method said "noCheck"... first line was check).
Fix will be in 2.8.5 (2.7 does not suffer from the issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants