Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson is not able to read json ChartOptions #179

Open
silvestrelosada opened this issue Apr 17, 2019 · 6 comments
Open

Jackson is not able to read json ChartOptions #179

silvestrelosada opened this issue Apr 17, 2019 · 6 comments

Comments

@silvestrelosada
Copy link

Trying to read ChartOptions from json string. ChartOptions has same method name for backgroundCollor and it is causing issues.

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "backgroundColor":

@martin-g
Copy link
Contributor

martin-g commented Apr 18, 2019

How does the JSON string looks like ?

The two setters are:

public ChartOptions setBackgroundColor(final Color color) {
		this.backgroundColor = new SimpleColor(color);
		return this;
	}

	public ChartOptions setBackgroundColor(final ColorReference backgroundColor) {
		this.backgroundColor = backgroundColor;
		return this;
	}

It is interesting what is the type of the parameter Jackson constructed: Color or ColorReference.
I'd suggest to try with latest version of Jackson (2.9.8) and if it still fails then to open a bug report at Jackson. It should be possible to resolve the correct setter if the parameter type is one of those two.

@silvestrelosada
Copy link
Author

That parameter was not specified the same happens with Options object and setColor.

@martin-g
Copy link
Contributor

Please paste the JSON string that use have used.

@silvestrelosada
Copy link
Author

silvestrelosada commented Apr 18, 2019

Here is an example

	public static void main(String[] args) {
		JsonRenderer render = new JsonRenderer();
		String charOptions = "{\"chart\":{\"renderTo\":\"container\",\"type\":\"bar\"},\"title\":{\"text\":\"Fruit Consumption\"},\"xAxis\":{\"categories\":[\"Apples\",\"Bananas\",\"Oranges\"]},\"yAxis\":{\"title\":{\"text\":\"Fruit eaten\"}},\"series\":[{\"name\":\"Jane\",\"data\":[1,0,4]},{\"name\":\"John\",\"data\":[5,7,3]}]}";
		Options chartOptions = render.fromJson(charOptions, Options.class);

		System.out.println(chartOptions);
	}

The json object

{  
   "chart":{  
      "renderTo":"container",
      "type":"bar"
   },
   "title":{  
      "text":"Fruit Consumption"
   },
   "xAxis":{  
      "categories":[  
         "Apples",
         "Bananas",
         "Oranges"
      ]
   },
   "yAxis":{  
      "title":{  
         "text":"Fruit eaten"
      }
   },
   "series":[  
      {  
         "name":"Jane",
         "data":[  
            1,
            0,
            4
         ]
      },
      {  
         "name":"John",
         "data":[  
            5,
            7,
            3
         ]
      }
   ]
}```

And this is the exception

Caused by: java.lang.IllegalArgumentException: Conflicting setter definitions for property "colors": de.adesso.wickedcharts.highcharts.options.Options#setColors(1 params) vs de.adesso.wickedcharts.highcharts.options.Options#setColors(1 params)

@silvestrelosada
Copy link
Author

Much better example case, Im generating an options object, then Im serializing it into json string and then I'm trying to read it, It also fails.

	public static void main(String[] args) {
		JsonRenderer render = new JsonRenderer();
		Options options = new Options();

	    options
	        .setChartOptions(new ChartOptions()
	            .setType(SeriesType.LINE));

	    options
	        .setTitle(new Title("My very own chart."));

	    options
	        .setxAxis(new Axis()
	            .setCategories(Arrays
	                .asList(new String[] { "Jan", "Feb", "Mar", "Apr", "May",
	                    "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })));

	    options
	        .setyAxis(new Axis()
	            .setTitle(new Title("Temperature (C)")));

	    options
	        .setLegend(new Legend()
	            .setLayout(LegendLayout.VERTICAL)
	            .setAlign(HorizontalAlignment.RIGHT)
	            .setVerticalAlign(VerticalAlignment.TOP)
	            .setX(-10)
	            .setY(100)
	            .setBorderWidth(0));

	    options
	        .addSeries(new SimpleSeries()
	            .setName("Tokyo")
	            .setData(
	                Arrays
	                    .asList(new Number[] { 7.0, 6.9, 9.5, 14.5, 18.2, 21.5,
	                        25.2, 26.5, 23.3, 18.3, 13.9, 9.6 })));

	    options
	        .addSeries(new SimpleSeries()
	            .setName("New York")
	            .setData(
	                Arrays
	                    .asList(new Number[] { -0.2, 0.8, 5.7, 11.3, 17.0, 22.0,
	                        24.8, 24.1, 20.1, 14.1, 8.6, 2.5 })));
		System.out.println(options);
		String optionsStr =  render.toJson(options);
		System.out.println(optionsStr);
		options = render.fromJson(optionsStr, Options.class);
		System.out.println(options);
	}

@simbajava
Copy link

Hi everybody
I was trying the library and its working perfect, thanks for the nice work.

My use case is as well let customers define a chart by providing the json and i am facing the exact same issue. Even writing to and then reading again the same json is not working as described by silvestrelosada 's last comment.

Do you find any solution yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants