File tree 3 files changed +31
-5
lines changed
main/java/net/dv8tion/jda/api/utils/data
3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 18
18
19
19
import com .fasterxml .jackson .core .JsonProcessingException ;
20
20
import com .fasterxml .jackson .databind .ObjectMapper ;
21
+ import com .fasterxml .jackson .databind .module .SimpleModule ;
21
22
import com .fasterxml .jackson .databind .type .CollectionType ;
22
23
import net .dv8tion .jda .api .exceptions .ParsingException ;
23
24
import org .jetbrains .annotations .Contract ;
44
45
public class DataArray implements Iterable <Object >
45
46
{
46
47
private static final Logger log = LoggerFactory .getLogger (DataObject .class );
47
- private static final ObjectMapper mapper = new ObjectMapper ();
48
- private static final CollectionType listType = mapper .getTypeFactory ().constructCollectionType (List .class , Object .class );
48
+ private static final ObjectMapper mapper ;
49
+ private static final SimpleModule module ;
50
+ private static final CollectionType listType ;
51
+
52
+ static
53
+ {
54
+ mapper = new ObjectMapper ();
55
+ module = new SimpleModule ();
56
+ module .addAbstractTypeMapping (Map .class , HashMap .class );
57
+ module .addAbstractTypeMapping (List .class , ArrayList .class );
58
+ mapper .registerModule (module );
59
+ listType = mapper .getTypeFactory ().constructRawCollectionType (ArrayList .class );
60
+ }
49
61
50
62
protected final List <Object > data ;
51
63
Original file line number Diff line number Diff line change 18
18
19
19
import com .fasterxml .jackson .core .JsonProcessingException ;
20
20
import com .fasterxml .jackson .databind .ObjectMapper ;
21
+ import com .fasterxml .jackson .databind .module .SimpleModule ;
21
22
import com .fasterxml .jackson .databind .type .MapType ;
22
23
import net .dv8tion .jda .api .exceptions .ParsingException ;
23
24
import org .jetbrains .annotations .Contract ;
44
45
public class DataObject implements SerializableData
45
46
{
46
47
private static final Logger log = LoggerFactory .getLogger (DataObject .class );
47
- private static final ObjectMapper mapper = new ObjectMapper ();
48
- private static final MapType mapType = mapper .getTypeFactory ().constructMapType (Map .class , String .class , Object .class );
48
+ private static final ObjectMapper mapper ;
49
+ private static final SimpleModule module ;
50
+ private static final MapType mapType ;
51
+
52
+ static
53
+ {
54
+ mapper = new ObjectMapper ();
55
+ module = new SimpleModule ();
56
+ module .addAbstractTypeMapping (Map .class , HashMap .class );
57
+ module .addAbstractTypeMapping (List .class , ArrayList .class );
58
+ mapper .registerModule (module );
59
+ mapType = mapper .getTypeFactory ().constructRawMapType (HashMap .class );
60
+ }
49
61
50
62
protected final Map <String , Object > data ;
51
63
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ public void testParse()
36
36
public void testJsonToString ()
37
37
{
38
38
DataObject object = DataObject .fromJson (json );
39
- Assertions .assertEquals (json , object .toString ()); // lucky that this works here :)
39
+ String result = object .toString ();
40
+ DataObject symmetric = DataObject .fromJson (result );
41
+ Assertions .assertEquals (object .toMap (), symmetric .toMap ()); // lucky that this works here :)
40
42
}
41
43
}
You can’t perform that action at this time.
0 commit comments