unnik
unnik

Reputation: 1153

Convert HashMap with POJO as value to JSON String

I have to convert a hashmap which has a POJO as a value.

HashMap<String,HashMap<String,VisualizerBean>> visualizerMap = new HashMap<String,HashMap<String,VisualizerBean>>();

JSONObject histoGramJsonData = new JSONObject(visualizerMap);

But the json I get prints the class name,

"(39.995,40.185]":

{
    "_type": "JavaClass",
    "contentSum": null,
    "count": null,
    "_classname": "com.fractal.cascade.chart.didq.VariableVisualizerNodeModel$VisualizerBean",
    "class": "com.fractal.cascade.chart.didq.VariableVisualizerNodeModel$VisualizerBean",
    "contentMean": null
}

Upvotes: 0

Views: 369

Answers (2)

Maurice Perry
Maurice Perry

Reputation: 32831

Yes; if that's a problem for you, you may want to use another json library such as Gson or Jackson.

Upvotes: 1

HyLian
HyLian

Reputation: 5093

Is this Android?

Android doc says:

Values may be any mix of JSONObjects, JSONArrays, Strings, Booleans, Integers, Longs, Doubles or NULL.

As com.fractal.cascade.chart.didq.VariableVisualizerNodeModel$VisualizerBean is not anything from above, it will call @Override toString() of that class.

Upvotes: 0

Related Questions