felldo opened a new issue, #2082:
URL: https://github.com/apache/fury/issues/2082

   ### Question
   
   Hi, I auto generate code in a `build.gradle.kts` file. Now I want to 
serialize the data in kotlin. On my application startup which is written in 
Java I want to read the file from the resources folder. 
   Serializing an empty `Map` works in Kotlin(when deserializing it afterwards 
in Java) but when adding an object to the Map it starts throwing this error 
(deserializing in java). When serializating from within Java, with the exact 
same object added to the map it works though.
   
   ```
   201
   java.lang.ArrayIndexOutOfBoundsException: 201
        at 
org.apache.fury.resolver.ClassResolver.getClassInfo(ClassResolver.java:1103)
        at 
org.apache.fury.resolver.ClassResolver.readClassInfo(ClassResolver.java:1723)
        at 
org.apache.fury.serializer.collection.AbstractMapSerializer.readJavaChunk(AbstractMapSerializer.java:767)
        at 
org.apache.fury.serializer.collection.AbstractMapSerializer.readElements(AbstractMapSerializer.java:641)
        at 
org.apache.fury.serializer.collection.AbstractMapSerializer.read(AbstractMapSerializer.java:610)
        at org.apache.fury.Fury.readDataInternal(Fury.java:972)
        at org.apache.fury.Fury.readRef(Fury.java:865)
        at org.apache.fury.Fury.deserialize(Fury.java:797)
        at org.apache.fury.Fury.deserialize(Fury.java:718)
   ```
   
   Serialization:
   ```kotlin
   val fury: Fury = Fury.builder().withLanguage(Language.JAVA)
               .requireClassRegistration(true)
               .withRefTracking(false)
               .build()
   
   KotlinSerializers.registerSerializers(fury)
   
   fury.register(Emoji::class.java)
   fury.register(EmojiGroup::class.java)
   fury.register(EmojiSubGroup::class.java)
   fury.register(Qualification::class.java)
   
   val emojiMap: MutableMap<String, Emoji> = mutableMapOf()
   
   emojiMap["test"] = Emoji(
               "🤼",
               "\\uD83E\\uDD3C",
               "&#129340;",
               "&#x1F93C;",
               "%F0%9F%A4%BC",
               Collections.unmodifiableList(Arrays.asList(":people_wrestling:", 
":wrestlers:", ":wrestling:")),
               Collections.singletonList(":wrestlers:"),
               Collections.singletonList(":wrestling:"),
               Collections.unmodifiableList(Arrays.asList("combat", "duel", 
"grapple", "people", "ring", "tournament", "wrestle", "wrestling")),
               false,
               false,
               3.0,
               Qualification.FULLY_QUALIFIED,
               "people wrestling",
               EmojiGroup.PEOPLE_AND_BODY,
               EmojiSubGroup.PERSON_SPORT,
               false
           )
   
   FileOutputStream(RESOURCES_PATH).use { out ->
       out.write(fury.serialize(emojiMap))
   }
   ```
   
   Deserialization:
   ```java
   static byte[] readFileAsBytes(final String filePathName) {
               try (InputStream is = 
EmojiManager.class.getResourceAsStream(filePathName); ByteArrayOutputStream 
buffer = new ByteArrayOutputStream()) {
           if (null == is) throw new IllegalStateException("InputStream is 
null");
   
           byte[] data = new byte[4096];
           int bytesRead;
           while ((bytesRead = is.read(data, 0, data.length)) != -1) {
               buffer.write(data, 0, bytesRead);
           }
           return buffer.toByteArray();
       } catch (IOException e) {
           throw new RuntimeException(e);
       }
   }
   
   public static void main(String... args) {
     final Fury fury = Fury.builder().withLanguage(Language.JAVA)
                             .requireClassRegistration(true)
                             .withAsyncCompilation(true)
                             .withRefTracking(false)
                             .build();
   
     fury.register(Emoji.class);
     fury.register(EmojiGroup.class);
     fury.register(EmojiSubGroup.class);
     fury.register(Qualification.class);
   
     Map<String, Emoji> map = (Map<String, Emoji>) 
fury.deserialize(readFileAsBytes("/single"));
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to