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

Cannot deserialize byte[] from JSON null value #107

Closed
reed53 opened this issue Oct 10, 2023 · 6 comments
Closed

Cannot deserialize byte[] from JSON null value #107

reed53 opened this issue Oct 10, 2023 · 6 comments
Labels
2.15 has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue
Milestone

Comments

@reed53
Copy link

reed53 commented Oct 10, 2023

Hello,
I ran into a bug today that I don't see a workaround for.
If I have an object like so:

  @Setter
  @Getter
  public static class ObjectWithByteArray {
      private byte[] arr;
  }

and I try to deserialize "{\"arr\":null}", I get the following error:

com.fasterxml.jackson.core.JsonParseException: Current token (VALUE_NULL) not VALUE_STRING or VALUE_EMBEDDED_OBJECT, can not access as binary
 at [Source: (String)"{"arr":null}"; line: 1, column: 12]

I then tried to implement a custom reader for byte arrays to work around this issue, however it seems like the error occurred before the reader has access to the value.

@cowtowncoder
Copy link
Member

cowtowncoder commented Oct 10, 2023

Could you please include a full reproduction, without using @Setter / @Getter annotations, and specifically include call you use for jackson-jr. Code snippets do not necessarily allow us to reproduce exact issue and we end up wasting time figuring out exact details otherwise.

It is possible this could be recreated from description, I've just had some bad experiences where submitter has omitted crucial details on calls being made, or (in some case) interaction with frameworks like Lombok.

@cowtowncoder cowtowncoder added the need-test-case To work on issue, a reproduction (ideally unit test) needed label Oct 10, 2023
@cowtowncoder cowtowncoder changed the title Byte array cannot be null Cannot deserialize byte[] from JSON null value Oct 10, 2023
@reed53
Copy link
Author

reed53 commented Oct 10, 2023

No worries! Here is a java program that when executed, reproduces the bug:

import com.fasterxml.jackson.jr.ob.JSON;
import java.io.IOException;

public class Test {

    public static void main(String[] args) throws IOException {
        var serialized = "{\"arr\":null}";
        var mapper = JSON.builder().build();

        var deserialized = mapper.beanFrom(ObjectWithByteArray.class, serialized);

        System.out.println(deserialized);
    }

    public static class ObjectWithByteArray {
        private byte[] arr;

        public byte[] getArr() {
            return arr;
        }

        public void setArr(byte[] arr) {
            this.arr = arr;
        }
    }
}

@cowtowncoder
Copy link
Member

Excellent, thank you @reed53 ! Definitely looks like a bug.

@cowtowncoder cowtowncoder added has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue and removed need-test-case To work on issue, a reproduction (ideally unit test) needed labels Oct 10, 2023
cowtowncoder added a commit that referenced this issue Oct 10, 2023
@cowtowncoder
Copy link
Member

Fixed for 2.15(.3) / 2.16(.0).

@reed53
Copy link
Author

reed53 commented Oct 11, 2023

Do you know how long it may be until a release?

@cowtowncoder cowtowncoder added this to the 2.15.3 milestone Oct 11, 2023
@cowtowncoder
Copy link
Member

@reed53 Unfortunately hard to predict, BUT, I am hoping to get first 2.16 release candidate out within this or next week. And would make sense to release 2.15.3 at around same time. So I think it can go out within 2 weeks if and when I find time (release takes 2-4 hours for the whole Jackson set)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.15 has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants