GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JsonObject deserialisation · Issue #883 · msgpack/msgpack-java

JsonObject deserialisation #883

New issue
Copy link
New issue
Copy link
Open
Open
JsonObject deserialisation#883
Copy link

Description

@ashj11
ashj11
opened on Apr 2, 2025
Issue body actions

I am using JsonReader to read json bytes to JsonObject. What is the equivalent for msgpack?
Below is the code we are using for desrialising json to JsonObject.

JsonReader jsonReader = Json.createReader(content);
            object =  jsonReader.readObject();
            jsonReader.close();

For deserialising JsonObject msgpack bytes to JsonObject in java, I have tried ObjectMapper, but it fails with

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot find a deserializer for non-concrete Map type [map type; class jakarta.json.JsonObject, [simple type, class java.lang.String] -> [simple type, class jakarta.json.JsonValue]]

Below is the sample i have tried, which produces above error. What is the right way to deserialise a JsonObject in msgpack?

String nodeInfo = "{\n" +
        "\t\"nodeType\": \"directory\"\n" +
        "}";
    
    // Create JsonObject from nodeInfo string
    JsonObject node;
    try (jakarta.json.JsonReader jsonReader = jakarta.json.Json.createReader(new ByteArrayInputStream(nodeInfo.getBytes(StandardCharsets.UTF_8)))) {
        node = jsonReader.readObject();
    }

    // Create MessagePack data
    ObjectMapper msgpackMapper = new ObjectMapper(new MessagePackFactory());
    byte[] bytes = msgpackMapper.writeValueAsBytes(node);

From #465 (comment), it looks like with ObjectMapper, JsonObject deserialisation used to work before. But it does not work now. Could you please suggest a solution?

Versions used:
jackson version - 2.15.3
msgpack version - 0.9.7

Activity

  1. komamitsu commented on Apr 5, 2025

    @komamitsu
    komamitsu
    on Apr 5, 2025
    Member
    More actions

    @ashj11 Can you confirm the issue doesn't happen with com.fasterxml.jackson.core:jackson-databind? If the issue doesn't occur with com.fasterxml.jackson.core:jackson-databind but it occurs with org.msgpack:jackson-dataformat-msgpack, it's a bug of this project and I can look into it.

  2. ashj11 commented on Apr 7, 2025

    @ashj11
    ashj11
    on Apr 7, 2025
    Author
    More actions

    Please ignore the second part of my question. I had tested with a String value and hence it was not able to decode to a class.

    But want to know more about decoding the msgpack bytes to a JsonObject. I have made it work using custom code with MessageUnpacker. It would have been great if there was a utility to unpack hierarchical content for all types similar to Json.createReader(content).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.