Skip to content

Commit

Permalink
bug fix for kotlin JSONB support, fix issue #440
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jun 9, 2022
1 parent 2c3ff82 commit 95407d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ public void writeJSONB(JSONWriter jsonWriter, Object object, Object fieldName, T
}

if (entryKey instanceof String || (contextFeatures & JSONWriter.Feature.WriteClassName.mask) == 0) {
String key = (String) entryKey;
String key;
if (entryKey instanceof String) {
key = (String) entryKey;
} else {
key = entryKey.toString();
}

if (symbolTable != null) {
jsonWriter.writeSymbol(key);
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/issues/Issue440.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.alibaba.fastjson2.issues

import com.alibaba.fastjson2.JSONB
import org.junit.jupiter.api.Test

class Issue440 {
class User { val map = mapOf(1 to 2, "a" to "a", 3f to 3f) }

@Test
fun test() {
val user = User()
val bytes = JSONB.toBytes(user)
}
}

0 comments on commit 95407d2

Please sign in to comment.