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 — jackson-dataformat-msgpack can't handle numbers as String type · Issue #421 · msgpack/msgpack-java

jackson-dataformat-msgpack can't handle numbers as String type #421

New issue
Copy link
New issue
Copy link
Closed
Closed
jackson-dataformat-msgpack can't handle numbers as String type#421
Copy link

Description

@komamitsu
komamitsu
opened on May 11, 2017
Issue body actions

I found this code fails while it works with replacing new ObjectMapper(new MessagePackFactory()) with new ObjectMapper().

    public static class MyIntegerSerializer
        extends JsonSerializer<Integer>
    {
        @Override
        public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers)
                throws IOException, JsonProcessingException
        {
            gen.writeNumber(String.valueOf(value));
        }
    }

    public static class MyIntegerDeserializer
            extends JsonDeserializer<Integer>
    {
        @Override
        public Integer deserialize(JsonParser p, DeserializationContext ctxt)
                throws IOException, JsonProcessingException
        {
            return p.getNumberValue().intValue();
        }
    }

    public static void main(String[] args)
            throws IOException
    {
        ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
        objectMapper.registerModule(
                new SimpleModule()
                        .addSerializer(Integer.class, new MyIntegerSerializer())
                        .addDeserializer(Integer.class, new MyIntegerDeserializer())
        );
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        objectMapper.writeValue(out, 42);

        Integer integer = objectMapper.readValue(out.toByteArray(), Integer.class);
        System.out.println(integer);
    }

>>>> com.fasterxml.jackson.databind.JsonMappingException: writeNumber(String encodedValue) isn't supported yet

Activity

  1. komamitsu
    closed this as completedin #422on May 15, 2017
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 01402520 — 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.