[Git][java-team/msgpack-java][master] 4 commits: New upstream version 0.8.22

Andrius Merkys gitlab at salsa.debian.org
Mon Dec 21 07:39:13 GMT 2020



Andrius Merkys pushed to branch master at Debian Java Maintainers / msgpack-java


Commits:
f5a07270 by Andrius Merkys at 2020-12-21T02:10:38-05:00
New upstream version 0.8.22
- - - - -
d18b02ff by Andrius Merkys at 2020-12-21T02:10:42-05:00
Update upstream source from tag 'upstream/0.8.22'

Update to upstream version '0.8.22'
with Debian dir ed74059028cf225024dce4af3fedef5f182fb18e
- - - - -
f6c7bf1a by Andrius Merkys at 2020-12-21T02:11:07-05:00
Refreshing patches.

- - - - -
e0c7ba8c by Andrius Merkys at 2020-12-21T02:12:10-05:00
Update changelog for 0.8.22-1 release

- - - - -


12 changed files:

- .github/workflows/CI.yml
- RELEASE_NOTES.md
- debian/changelog
- debian/patches/ignore-failing-tests.patch
- msgpack-jackson/README.md
- msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/ExtensionTypeCustomDeserializers.java
- msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java
- msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java
- msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackFactoryTest.java
- msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackGeneratorTest.java
- msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackParserTest.java
- version.sbt


Changes:

=====================================
.github/workflows/CI.yml
=====================================
@@ -29,7 +29,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout at v2
-      - uses: olafurpg/setup-scala at v7
+      - uses: olafurpg/setup-scala at v10
         with:
           java-version: adopt at 1.11
       - uses: actions/cache at v2
@@ -46,7 +46,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout at v2
-      - uses: olafurpg/setup-scala at v7
+      - uses: olafurpg/setup-scala at v10
         with:
           java-version: adopt at 1.8
       - uses: actions/cache at v2


=====================================
RELEASE_NOTES.md
=====================================
@@ -1,5 +1,10 @@
 # Release Notes
 
+## 0.8.22
+ * Support extension type key in Map [#535](https://github.com/msgpack/msgpack-java/pull/535)
+ * Remove addTargetClass() and addTargetTypeReference() from ExtensionTypeCustomDeserializers [#539](https://github.com/msgpack/msgpack-java/pull/539)
+ * Fix a bug BigDecimal serializaion fails [#540](https://github.com/msgpack/msgpack-java/pull/540)
+
 ## 0.8.21
  * Fix indexing bug in ValueFactory [#525](https://github.com/msgpack/msgpack-java/pull/525)
  * Support numeric types in MessagePackParser.getText() [#527](https://github.com/msgpack/msgpack-java/pull/527)


=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+msgpack-java (0.8.22-1) unstable; urgency=medium
+
+  * New upstream version 0.8.22
+  * Refreshing patches.
+
+ -- Andrius Merkys <merkys at debian.org>  Mon, 21 Dec 2020 02:12:06 -0500
+
 msgpack-java (0.8.21-1) unstable; urgency=medium
 
   * New upstream version 0.8.21


=====================================
debian/patches/ignore-failing-tests.patch
=====================================
@@ -11,7 +11,7 @@ Author: Andrius Merkys <merkys at debian.org>
  import org.junit.Test;
  import org.msgpack.core.ExtensionTypeHeader;
  import org.msgpack.core.MessagePack;
-@@ -642,6 +643,7 @@
+@@ -645,6 +646,7 @@
          }
      }
  
@@ -19,7 +19,7 @@ Author: Andrius Merkys <merkys at debian.org>
      @Test
      @SuppressWarnings("unchecked")
      public void testNonStringKey()
-@@ -696,6 +698,7 @@
+@@ -699,6 +701,7 @@
          }
      }
  
@@ -27,7 +27,7 @@ Author: Andrius Merkys <merkys at debian.org>
      @Test
      public void testComplexTypeKey()
              throws IOException
-@@ -717,6 +720,7 @@
+@@ -720,6 +723,7 @@
          assertThat(unpacker.unpackInt(), is(42));
      }
  


=====================================
msgpack-jackson/README.md
=====================================
@@ -207,113 +207,196 @@ When you want to use non-String value as a key of Map, use `MessagePackKeySerial
   @JsonSerialize(keyUsing = MessagePackKeySerializer.class)
   private Map<Integer, String> intMap = new HashMap<>();
 
-      :
-  {
-      intMap.put(42, "Hello");
+    :
 
-      ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
-      byte[] bytes = objectMapper.writeValueAsBytes(intMap);
+  intMap.put(42, "Hello");
 
-      Map<Integer, String> deserialized = objectMapper.readValue(bytes, new TypeReference<Map<Integer, String>>() {});
-      System.out.println(deserialized);   // => {42=Hello}
-  }
+  ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
+  byte[] bytes = objectMapper.writeValueAsBytes(intMap);
+
+  Map<Integer, String> deserialized = objectMapper.readValue(bytes, new TypeReference<Map<Integer, String>>() {});
+  System.out.println(deserialized);   // => {42=Hello}
 ```
 
 ### Deserialize extension types with ExtensionTypeCustomDeserializers
 
 `ExtensionTypeCustomDeserializers` helps you to deserialize extension types easily.
 
-#### With target Java class
+#### Deserialize extension type value directly
 
 ```java
-  NestedListComplexPojo parent = new NestedListComplexPojo();
-  parent.children = Arrays.asList(new TinyPojo("Foo"), new TinyPojo("Bar"));
-
-  // In this application, extension type 17 is used for NestedListComplexPojo
+  // In this application, extension type 59 is used for byte[]
   byte[] bytes;
   {
       // This ObjectMapper is just for temporary serialization
-      ObjectMapper tempObjectMapper = new ObjectMapper(new MessagePackFactory());
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       MessagePacker packer = MessagePack.newDefaultPacker(outputStream);
 
-      byte[] extBytes = tempObjectMapper.writeValueAsBytes(parent);
-      packer.packExtensionTypeHeader((byte) 17, extBytes.length);
-      packer.addPayload(extBytes);
+      packer.packExtensionTypeHeader((byte) 59, hexspeak.length);
+      packer.addPayload(hexspeak);
       packer.close();
 
       bytes = outputStream.toByteArray();
   }
 
-  // Register the type and the class to ExtensionTypeCustomDeserializers
+  // Register the type and a deserializer to ExtensionTypeCustomDeserializers
   ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
-  extTypeCustomDesers.addTargetClass((byte) 17, NestedListComplexPojo.class);
+  extTypeCustomDesers.addCustomDeser((byte) 59, data -> {
+      if (Arrays.equals(data,
+                new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE})) {
+          return "Java";
+      }
+      return "Not Java";
+  }
+  );
   ObjectMapper objectMapper = new ObjectMapper(
           new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers));
 
   System.out.println(objectMapper.readValue(bytes, Object.class));
-    // => NestedListComplexPojo{children=[TinyPojo{name='Foo'}, TinyPojo{name='Bar'}]}
+    // => Java
 ```
 
-#### With type reference
+#### Use extension type as Map key
 
 ```java
-  Map<String, Integer> map = new HashMap<>();
-  map.put("one", 1);
-  map.put("two", 2);
-
-  // In this application, extension type 31 is used for Map<String, Integer>
-  byte[] bytes;
+  static class TripleBytesPojo
   {
-      // Same as above
-        :
-      packer.packExtensionTypeHeader((byte) 31, extBytes.length);
-        :
+    public byte first;
+    public byte second;
+    public byte third;
+
+    public TripleBytesPojo(byte first, byte second, byte third)
+    {
+      this.first = first;
+      this.second = second;
+      this.third = third;
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+      :
+    }
+
+    @Override
+    public int hashCode()
+    {
+      :
+    }
+
+    @Override
+    public String toString()
+    {
+      // This key format is used when serialized as map key
+      return String.format("%d-%d-%d", first, second, third);
+    }
+
+    static class KeyDeserializer
+        extends com.fasterxml.jackson.databind.KeyDeserializer
+    {
+      @Override
+      public Object deserializeKey(String key, DeserializationContext ctxt)
+          throws IOException
+      {
+        String[] values = key.split("-");
+        return new TripleBytesPojo(Byte.parseByte(values[0]), Byte.parseByte(values[1]), Byte.parseByte(values[2]));
+      }
+    }
+
+    static TripleBytesPojo deserialize(byte[] bytes)
+    {
+      return new TripleBytesPojo(bytes[0], bytes[1], bytes[2]);
+    }
   }
 
-  // Register the type and the type reference to ExtensionTypeCustomDeserializers
+  :
+
+  byte extTypeCode = 42;
+
   ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
-  extTypeCustomDesers.addTargetTypeReference((byte) 31,
-  	      new TypeReference<Map<String, Integer>>() {});
+  extTypeCustomDesers.addCustomDeser(extTypeCode, new ExtensionTypeCustomDeserializers.Deser()
+  {
+    @Override
+    public Object deserialize(byte[] value)
+          throws IOException
+    {
+      return TripleBytesPojo.deserialize(value);
+    }
+  });
+
+  SimpleModule module = new SimpleModule();
+  module.addKeyDeserializer(TripleBytesPojo.class, new TripleBytesPojo.KeyDeserializer());
   ObjectMapper objectMapper = new ObjectMapper(
-          new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers));
+          new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers))
+              .registerModule(module);
 
-  System.out.println(objectMapper.readValue(bytes, Object.class));
-    // => {one=1, two=2}
+  Map<TripleBytesPojo, Integer> deserializedMap =
+          objectMapper.readValue(serializedData,
+              new TypeReference<Map<TripleBytesPojo, Integer>>() {});
 ```
 
-#### With custom deserializer
+#### Use extension type as Map value
 
 ```java
-  // In this application, extension type 59 is used for byte[]
-  byte[] bytes;
+  static class TripleBytesPojo
   {
-      // This ObjectMapper is just for temporary serialization
-      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-      MessagePacker packer = MessagePack.newDefaultPacker(outputStream);
+    public byte first;
+    public byte second;
+    public byte third;
 
-      packer.packExtensionTypeHeader((byte) 59, hexspeak.length);
-      packer.addPayload(hexspeak);
-      packer.close();
+    public TripleBytesPojo(byte first, byte second, byte third)
+    {
+      this.first = first;
+      this.second = second;
+      this.third = third;
+    }
 
-      bytes = outputStream.toByteArray();
-  }
+    static class Deserializer
+        extends StdDeserializer<TripleBytesPojo>
+    {
+      protected Deserializer()
+      {
+        super(TripleBytesPojo.class);
+      }
 
-  // Register the type and a deserializer to ExtensionTypeCustomDeserializers
-  ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
-  extTypeCustomDesers.addCustomDeser((byte) 59, data -> {
-      if (Arrays.equals(data,
-                new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE})) {
-          return "Java";
+      @Override
+      public TripleBytesPojo deserialize(JsonParser p, DeserializationContext ctxt)
+          throws IOException, JsonProcessingException
+      {
+        return TripleBytesPojo.deserialize(p.getBinaryValue());
       }
-      return "Not Java";
+    }
+
+    static TripleBytesPojo deserialize(byte[] bytes)
+    {
+      return new TripleBytesPojo(bytes[0], bytes[1], bytes[2]);
+    }
   }
-  );
+
+  :
+
+  byte extTypeCode = 42;
+
+  ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
+  extTypeCustomDesers.addCustomDeser(extTypeCode, new ExtensionTypeCustomDeserializers.Deser()
+  {
+    @Override
+    public Object deserialize(byte[] value)
+        throws IOException
+    {
+      return TripleBytesPojo.deserialize(value);
+    }
+  });
+
+  SimpleModule module = new SimpleModule();
+  module.addDeserializer(TripleBytesPojo.class, new TripleBytesPojo.Deserializer());
   ObjectMapper objectMapper = new ObjectMapper(
-          new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers));
+          new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers))
+              .registerModule(module);
 
-  System.out.println(objectMapper.readValue(bytes, Object.class));
-    // => Java
+  Map<String, TripleBytesPojo> deserializedMap =
+          objectMapper.readValue(serializedData,
+              new TypeReference<Map<String, TripleBytesPojo>>() {});
 ```
 
 ### Serialize a nested object that also serializes


=====================================
msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/ExtensionTypeCustomDeserializers.java
=====================================
@@ -15,21 +15,16 @@
 //
 package org.msgpack.jackson.dataformat;
 
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
 import java.io.IOException;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 public class ExtensionTypeCustomDeserializers
 {
-    private final ObjectMapper objectMapper;
-    private Map<Byte, Deser> deserTable = new ConcurrentHashMap<Byte, Deser>();
+    private Map<Byte, Deser> deserTable = new ConcurrentHashMap<>();
 
     public ExtensionTypeCustomDeserializers()
     {
-        objectMapper = new ObjectMapper(new MessagePackFactory().setReuseResourceInParser(false));
     }
 
     public ExtensionTypeCustomDeserializers(ExtensionTypeCustomDeserializers src)
@@ -38,32 +33,6 @@ public class ExtensionTypeCustomDeserializers
         this.deserTable.putAll(src.deserTable);
     }
 
-    public <T> void addTargetClass(byte type, final Class<T> klass)
-    {
-        deserTable.put(type, new Deser()
-        {
-            @Override
-            public Object deserialize(byte[] data)
-                    throws IOException
-            {
-                return objectMapper.readValue(data, klass);
-            }
-        });
-    }
-
-    public void addTargetTypeReference(byte type, final TypeReference typeReference)
-    {
-        deserTable.put(type, new Deser()
-        {
-            @Override
-            public Object deserialize(byte[] data)
-                    throws IOException
-            {
-                return objectMapper.readValue(data, typeReference);
-            }
-        });
-    }
-
     public void addCustomDeser(byte type, final Deser deser)
     {
         deserTable.put(type, new Deser()


=====================================
msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java
=====================================
@@ -270,7 +270,8 @@ public class MessagePackGenerator
         if (failedToPackAsBI) {
             double doubleValue = decimal.doubleValue();
             //Check to make sure this BigDecimal can be represented as a double
-            if (!decimal.stripTrailingZeros().toEngineeringString().equals(BigDecimal.valueOf(doubleValue).toEngineeringString())) {
+            if (!decimal.stripTrailingZeros().toEngineeringString().equals(
+                    BigDecimal.valueOf(doubleValue).stripTrailingZeros().toEngineeringString())) {
                 throw new IllegalArgumentException("MessagePack cannot serialize a BigDecimal that can't be represented as double. " + decimal);
             }
             messagePacker.packDouble(doubleValue);


=====================================
msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java
=====================================
@@ -341,7 +341,13 @@ public class MessagePackParser
                 type = Type.EXT;
                 ExtensionTypeHeader header = messageUnpacker.unpackExtensionTypeHeader();
                 extensionTypeValue = new MessagePackExtensionType(header.getType(), messageUnpacker.readPayload(header.getLength()));
-                nextToken = JsonToken.VALUE_EMBEDDED_OBJECT;
+                if (parsingContext.inObject() && _currToken != JsonToken.FIELD_NAME) {
+                    parsingContext.setCurrentName(deserializedExtensionTypeValue().toString());
+                    nextToken = JsonToken.FIELD_NAME;
+                }
+                else {
+                    nextToken = JsonToken.VALUE_EMBEDDED_OBJECT;
+                }
                 break;
             default:
                 throw new IllegalStateException("Shouldn't reach here");
@@ -391,6 +397,8 @@ public class MessagePackParser
                 return String.valueOf(doubleValue);
             case BIG_INT:
                 return String.valueOf(biValue);
+            case EXT:
+                return deserializedExtensionTypeValue().toString();
             default:
                 throw new IllegalStateException("Invalid type=" + type);
         }
@@ -432,6 +440,8 @@ public class MessagePackParser
                 return bytesValue;
             case STRING:
                 return stringValue.getBytes(MessagePack.UTF8);
+            case EXT:
+                return extensionTypeValue.getData();
             default:
                 throw new IllegalStateException("Invalid type=" + type);
         }
@@ -563,6 +573,18 @@ public class MessagePackParser
         }
     }
 
+    private Object deserializedExtensionTypeValue()
+            throws IOException
+    {
+        if (extTypeCustomDesers != null) {
+            ExtensionTypeCustomDeserializers.Deser deser = extTypeCustomDesers.getDeser(extensionTypeValue.getType());
+            if (deser != null) {
+                return deser.deserialize(extensionTypeValue.getData());
+            }
+        }
+        return extensionTypeValue;
+    }
+
     @Override
     public Object getEmbeddedObject()
             throws IOException, JsonParseException
@@ -571,13 +593,7 @@ public class MessagePackParser
             case BYTES:
                 return bytesValue;
             case EXT:
-                if (extTypeCustomDesers != null) {
-                    ExtensionTypeCustomDeserializers.Deser deser = extTypeCustomDesers.getDeser(extensionTypeValue.getType());
-                    if (deser != null) {
-                        return deser.deserialize(extensionTypeValue.getData());
-                    }
-                }
-                return extensionTypeValue;
+                return deserializedExtensionTypeValue();
             default:
                 throw new IllegalStateException("Invalid type=" + type);
         }


=====================================
msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackFactoryTest.java
=====================================
@@ -65,7 +65,19 @@ public class MessagePackFactoryTest
         ObjectMapper objectMapper;
         if (advancedConfig) {
             ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
-            extTypeCustomDesers.addTargetClass((byte) 42, TinyPojo.class);
+            extTypeCustomDesers.addCustomDeser((byte) 42,
+                    new ExtensionTypeCustomDeserializers.Deser()
+                    {
+                        @Override
+                        public Object deserialize(byte[] data)
+                                throws IOException
+                        {
+                            TinyPojo pojo = new TinyPojo();
+                            pojo.t = new String(data);
+                            return pojo;
+                        }
+                    }
+            );
 
             MessagePack.PackerConfig msgpackPackerConfig = new MessagePack.PackerConfig().withStr8FormatSupport(false);
 


=====================================
msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackGeneratorTest.java
=====================================
@@ -304,10 +304,12 @@ public class MessagePackGeneratorTest
             double d0 = 1.23456789;
             double d1 = 1.23450000000000000000006789;
             String d2 = "12.30";
+            String d3 = "0.00001";
             List<BigDecimal> bigDecimals = Arrays.asList(
                     BigDecimal.valueOf(d0),
                     BigDecimal.valueOf(d1),
                     new BigDecimal(d2),
+                    new BigDecimal(d3),
                     BigDecimal.valueOf(Double.MIN_VALUE),
                     BigDecimal.valueOf(Double.MAX_VALUE),
                     BigDecimal.valueOf(Double.MIN_NORMAL)
@@ -320,6 +322,7 @@ public class MessagePackGeneratorTest
             assertEquals(d0, unpacker.unpackDouble(), 0.000000000000001);
             assertEquals(d1, unpacker.unpackDouble(), 0.000000000000001);
             assertEquals(Double.valueOf(d2), unpacker.unpackDouble(), 0.000000000000001);
+            assertEquals(Double.valueOf(d3), unpacker.unpackDouble(), 0.000000000000001);
             assertEquals(Double.MIN_VALUE, unpacker.unpackDouble(), 0.000000000000001);
             assertEquals(Double.MAX_VALUE, unpacker.unpackDouble(), 0.000000000000001);
             assertEquals(Double.MIN_NORMAL, unpacker.unpackDouble(), 0.000000000000001);


=====================================
msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackParserTest.java
=====================================
@@ -25,10 +25,14 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.KeyDeserializer;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
 import com.fasterxml.jackson.databind.module.SimpleModule;
 import org.junit.Test;
 import org.msgpack.core.MessagePack;
 import org.msgpack.core.MessagePacker;
+import org.msgpack.value.ExtensionValue;
+import org.msgpack.value.MapValue;
+import org.msgpack.value.ValueFactory;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -44,10 +48,10 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -699,34 +703,12 @@ public class MessagePackParserTest
     {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         MessagePacker packer = MessagePack.newDefaultPacker(out);
-        packer.packArrayHeader(5);
+        packer.packArrayHeader(3);
         // 0: Integer
         packer.packInt(42);
         // 1: String
         packer.packString("foo bar");
-        // 2: ExtensionType(class desr)
-        {
-            TinyPojo t0 = new TinyPojo();
-            t0.t = "t0";
-            TinyPojo t1 = new TinyPojo();
-            t1.t = "t1";
-            NestedListComplexPojo parent = new NestedListComplexPojo();
-            parent.s = "parent";
-            parent.foos = Arrays.asList(t0, t1);
-            byte[] bytes = objectMapper.writeValueAsBytes(parent);
-            packer.packExtensionTypeHeader((byte) 17, bytes.length);
-            packer.addPayload(bytes);
-        }
-        // 3: ExtensionType(type reference deser)
-        {
-            Map<String, Integer> map = new HashMap<String, Integer>();
-            map.put("one", 1);
-            map.put("two", 2);
-            byte[] bytes = objectMapper.writeValueAsBytes(map);
-            packer.packExtensionTypeHeader((byte) 99, bytes.length);
-            packer.addPayload(bytes);
-        }
-        // 4: ExtensionType(custom deser)
+        // 2: ExtensionType
         {
             packer.packExtensionTypeHeader((byte) 31, 4);
             packer.addPayload(new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE});
@@ -734,8 +716,6 @@ public class MessagePackParserTest
         packer.close();
 
         ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
-        extTypeCustomDesers.addTargetClass((byte) 17, NestedListComplexPojo.class);
-        extTypeCustomDesers.addTargetTypeReference((byte) 99, new TypeReference<Map<String, Integer>>() {});
         extTypeCustomDesers.addCustomDeser((byte) 31, new ExtensionTypeCustomDeserializers.Deser() {
                     @Override
                     public Object deserialize(byte[] data)
@@ -752,27 +732,210 @@ public class MessagePackParserTest
                 new ObjectMapper(new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers));
 
         List<Object> values = objectMapper.readValue(new ByteArrayInputStream(out.toByteArray()), new TypeReference<List<Object>>() {});
-        assertThat(values.size(), is(5));
+        assertThat(values.size(), is(3));
         assertThat((Integer) values.get(0), is(42));
         assertThat((String) values.get(1), is("foo bar"));
+        assertThat((String) values.get(2), is("Java"));
+    }
+
+    static class TripleBytesPojo
+    {
+        public byte first;
+        public byte second;
+        public byte third;
+
+        public TripleBytesPojo(byte first, byte second, byte third)
+        {
+            this.first = first;
+            this.second = second;
+            this.third = third;
+        }
+
+        @Override
+        public boolean equals(Object o)
+        {
+            if (this == o) {
+                return true;
+            }
+            if (!(o instanceof TripleBytesPojo)) {
+                return false;
+            }
+
+            TripleBytesPojo that = (TripleBytesPojo) o;
+
+            if (first != that.first) {
+                return false;
+            }
+            if (second != that.second) {
+                return false;
+            }
+            return third == that.third;
+        }
+
+        @Override
+        public int hashCode()
+        {
+            int result = first;
+            result = 31 * result + (int) second;
+            result = 31 * result + (int) third;
+            return result;
+        }
+
+        @Override
+        public String toString()
         {
-            Object v = values.get(2);
-            assertThat(v, is(instanceOf(NestedListComplexPojo.class)));
-            NestedListComplexPojo pojo = (NestedListComplexPojo) v;
-            assertThat(pojo.s, is("parent"));
-            assertThat(pojo.foos.size(), is(2));
-            assertThat(pojo.foos.get(0).t, is("t0"));
-            assertThat(pojo.foos.get(1).t, is("t1"));
+            // This key format is used when serialized as map key
+            return String.format("%d-%d-%d", first, second, third);
         }
+
+        static class Deserializer
+                extends StdDeserializer<TripleBytesPojo>
         {
-            Object v = values.get(3);
-            assertThat(v, is(instanceOf(Map.class)));
-            Map<String, Integer> map = (Map<String, Integer>) v;
-            assertThat(map.size(), is(2));
-            assertThat(map.get("one"), is(1));
-            assertThat(map.get("two"), is(2));
+            protected Deserializer()
+            {
+                super(TripleBytesPojo.class);
+            }
+
+            @Override
+            public TripleBytesPojo deserialize(JsonParser p, DeserializationContext ctxt)
+                    throws IOException, JsonProcessingException
+            {
+                return TripleBytesPojo.deserialize(p.getBinaryValue());
+            }
+        }
+
+        static class KeyDeserializer
+                extends com.fasterxml.jackson.databind.KeyDeserializer
+        {
+            @Override
+            public Object deserializeKey(String key, DeserializationContext ctxt)
+                    throws IOException
+            {
+                String[] values = key.split("-");
+                return new TripleBytesPojo(
+                        Byte.parseByte(values[0]),
+                        Byte.parseByte(values[1]),
+                        Byte.parseByte(values[2]));
+            }
+        }
+
+        static byte[] serialize(TripleBytesPojo obj)
+        {
+            return new byte[] { obj.first, obj.second, obj.third };
+        }
+
+        static TripleBytesPojo deserialize(byte[] bytes)
+        {
+            return new TripleBytesPojo(bytes[0], bytes[1], bytes[2]);
+        }
+    }
+
+    @Test
+    public void extensionTypeWithPojoInMap()
+            throws IOException
+    {
+        byte extTypeCode = 42;
+
+        ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
+        extTypeCustomDesers.addCustomDeser(extTypeCode, new ExtensionTypeCustomDeserializers.Deser()
+        {
+            @Override
+            public Object deserialize(byte[] value)
+                    throws IOException
+            {
+                return TripleBytesPojo.deserialize(value);
+            }
+        });
+
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(TripleBytesPojo.class, new TripleBytesPojo.Deserializer());
+        module.addKeyDeserializer(TripleBytesPojo.class, new TripleBytesPojo.KeyDeserializer());
+        ObjectMapper objectMapper = new ObjectMapper(
+                new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers))
+                .registerModule(module);
+
+        // Prepare serialized data
+        Map<TripleBytesPojo, TripleBytesPojo> originalMap = new HashMap<>();
+        byte[] serializedData;
+        {
+            ValueFactory.MapBuilder mapBuilder = ValueFactory.newMapBuilder();
+            for (int i = 0; i < 4; i++) {
+                TripleBytesPojo keyObj = new TripleBytesPojo((byte) i, (byte) (i + 1), (byte) (i + 2));
+                TripleBytesPojo valueObj = new TripleBytesPojo((byte) (i * 2), (byte) (i * 3), (byte) (i * 4));
+                ExtensionValue k = ValueFactory.newExtension(extTypeCode, TripleBytesPojo.serialize(keyObj));
+                ExtensionValue v = ValueFactory.newExtension(extTypeCode, TripleBytesPojo.serialize(valueObj));
+                mapBuilder.put(k, v);
+                originalMap.put(keyObj, valueObj);
+            }
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            MessagePacker packer = MessagePack.newDefaultPacker(output);
+            MapValue mapValue = mapBuilder.build();
+            mapValue.writeTo(packer);
+            packer.close();
+
+            serializedData = output.toByteArray();
+        }
+
+        Map<TripleBytesPojo, TripleBytesPojo> deserializedMap = objectMapper.readValue(serializedData,
+                new TypeReference<Map<TripleBytesPojo, TripleBytesPojo>>() {});
+
+        assertEquals(originalMap.size(), deserializedMap.size());
+        for (Map.Entry<TripleBytesPojo, TripleBytesPojo> entry : originalMap.entrySet()) {
+            assertEquals(entry.getValue(), deserializedMap.get(entry.getKey()));
+        }
+    }
+
+    @Test
+    public void extensionTypeWithUuidInMap()
+            throws IOException
+    {
+        byte extTypeCode = 42;
+
+        ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
+        extTypeCustomDesers.addCustomDeser(extTypeCode, new ExtensionTypeCustomDeserializers.Deser()
+        {
+            @Override
+            public Object deserialize(byte[] value)
+                    throws IOException
+            {
+                return UUID.fromString(new String(value));
+            }
+        });
+
+        // In this case with UUID, we don't need to add custom deserializers
+        // since jackson-databind already has it.
+        ObjectMapper objectMapper = new ObjectMapper(
+                new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers));
+
+        // Prepare serialized data
+        Map<UUID, UUID> originalMap = new HashMap<>();
+        byte[] serializedData;
+        {
+            ValueFactory.MapBuilder mapBuilder = ValueFactory.newMapBuilder();
+            for (int i = 0; i < 4; i++) {
+                UUID keyObj = UUID.randomUUID();
+                UUID valueObj = UUID.randomUUID();
+                ExtensionValue k = ValueFactory.newExtension(extTypeCode, keyObj.toString().getBytes());
+                ExtensionValue v = ValueFactory.newExtension(extTypeCode, valueObj.toString().getBytes());
+                mapBuilder.put(k, v);
+                originalMap.put(keyObj, valueObj);
+            }
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            MessagePacker packer = MessagePack.newDefaultPacker(output);
+            MapValue mapValue = mapBuilder.build();
+            mapValue.writeTo(packer);
+            packer.close();
+
+            serializedData = output.toByteArray();
+        }
+
+        Map<UUID, UUID> deserializedMap = objectMapper.readValue(serializedData,
+                new TypeReference<Map<UUID, UUID>>() {});
+
+        assertEquals(originalMap.size(), deserializedMap.size());
+        for (Map.Entry<UUID, UUID> entry : originalMap.entrySet()) {
+            assertEquals(entry.getValue(), deserializedMap.get(entry.getKey()));
         }
-        assertThat((String) values.get(4), is("Java"));
     }
 
     @Test


=====================================
version.sbt
=====================================
@@ -1 +1 @@
-version in ThisBuild := "0.8.21"
+version in ThisBuild := "0.8.22"



View it on GitLab: https://salsa.debian.org/java-team/msgpack-java/-/compare/77de515d1463aa165aac202e3a0b8ef77e1a7b27...e0c7ba8cb44f4da1447ac8f8bbfce8896a05ea3e

-- 
View it on GitLab: https://salsa.debian.org/java-team/msgpack-java/-/compare/77de515d1463aa165aac202e3a0b8ef77e1a7b27...e0c7ba8cb44f4da1447ac8f8bbfce8896a05ea3e
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20201221/817d94d4/attachment.html>


More information about the pkg-java-commits mailing list