Jersey/Jaxb is providing a result of strings rather than numbers

This is the structure that my jersey service returns:

@XmlRootElement(name="chart-data")
public class ChartDataDto {
    private List<Series> series = new ArrayList<>();

    public ChartDataDto() {
        
    }

    public void putSeries(String name, Integer... series) {
        this.series.add(new Series(name, series));
    }

    @XmlElement(name="series")
    public List<Series> getSeries() {
        return this.series;
    }

    @XmlRootElement(name="series")
    static class Series {
        @XmlElement(name="name")
        public String name;
        @XmlElement(name="values")
        public List<Integer> series;

        public Series() {
            
        }

        public Series(String name, Integer... series) {
            this.name = name;
            this.series = Arrays.asList(series);
        }
    }
}

The JSON string returned looks like this:

{"series":[
    {
        "name":"Series 1",
        "values":["1","2","2","3","3","4","4","5","5","6","6","7","7"]
    },{
        "name":"Series 2",
        "values":["7","7","6","6","5","5","4","4","3","3","2","2","1"]
    }
]}

However, there seems to be an issue with the JSON string. The correct JSON format should be:

{"series":[
    {
        "name":"Series 1",
        "values":[1,2,2,3,3,4,4,5,5,6,6,7,7]
    },{
        "name":"Series 2",
        "values":[7,7,6,6,5,5,4,4,3,3,2,2,1]
    }
]}

What could be causing the problem? Could it be the data type for the integer list or the annotations used?

Answer №1

Your code functions perfectly with the combination of Jackson and Gson.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to automatically clear the text field value after submitting?

Greetings everyone, I'm looking for guidance on removing the text field content once I click submit. I have a button labeled "senden" and my goal is to clear the text fields and uncheck the checkbox after clicking this button. I've attempted se ...

There was a problem finding the correct address indicated by the marker

I am working on an Android app using PhoneGap, and I need to display a marker on a Google map at a specific latitude and longitude. When the marker is clicked, I want to show an info window displaying the address associated with that location. However, t ...

Generating a multidimensional array using a list of JSON objects

My task involves working with a JSON feed that contains a list of objects, each with its own id and idParent. The objects with an idParent of null are considered the base parent elements. I want to create a multidimensional array resembling a tree view, ke ...

Is it possible to use an angular expression as the ng-click function?

I have been searching everywhere for the answer to this question. Within my code, there is an angular object called column.addOnParams. This object includes a child element named rowClick, which can be accessed using column.addOnParams.rowClick. The val ...

A dynamic modal window built with ReactJS

I am struggling to understand how to make my app function properly. There is a component called ContactAdd that should render the component ModalWindow when clicked. The ModalWindow component requires a parameter called isOpened={this.state.open}. How c ...

Add a CSS class to the text that is selected within a Content Editable div

Hey there, I'm having an issue where the class is being applied to the button when pressed instead of the selected text. Here's my current code: The button needs to be a div, but it might be causing the problem. I just want the highlighted text ...

Modifying APK files programmatically using Java

This question may be a bit complex, so please bear with me as I explain my issue: I am trying to programmatically modify an apk file after installation. I have been using another app for editing purposes. Initially, I tried to achieve this using the built- ...

Is there a way for me to produce a random choice depending on the option selected by the user in the <select> menu?

As a beginner in JavaScript, I am attempting to create a feature where users can select a genre from a dropdown list and receive a random recommendation from that genre displayed on the screen. In essence, my goal is to allow users to get a random suggest ...

Issue: req.flash() not functioning correctly following the execution of req.session.destroy()

In order to log the user out and redirect them to a login page with a message under specific conditions, it is necessary to destroy the user's current session. I usually use the flash feature to display a one-time message in my application, which work ...

Tips for saving/downloading generated QR codes in React Native

Using this code allows me to generate QR Codes, but I am struggling with saving the generated QR Code in PNG or JPEG format. I have tried a few examples without success and I am continuing to try different methods. import React, { Component } from 'r ...

Is there a more effective approach to managing an array of objects retrieved from an API call?

I'm attempting to extract an array of names from a JSON response that contains an array of objects, but I'm running into issues. When I try to print the array, it shows up empty. Is this the correct way to go about it? There don't seem to be ...

The dialogue box fails to appear when accessed from the dropdown menu shadcn

I'm encountering an issue while using nextJS with shadcn. I am attempting to open a dialog from a dropdown menu, but instead of opening, it just closes the dropdown menu. My assumption is that I either need to utilize ref and states or position the al ...

Generate a dynamic add to cart section for every last configurable choice, assisting with this task

Currently, I am involved in a project that involves displaying configurable options on a product page, along with querying the database to check which vendors carry the product. The list of vendors is then displayed using JavaScript. In order to make the ...

Sending the parameter with the URL and receiving the response in return

Can the result be retrieved by calling a URL and sending specific parameters with it? For instance, if I pass two numbers along with the URL, can I receive the sum in return? The addition operation is carried out on the page being called upon. ...

Content within a Row of a Data Table

Hello! I am just starting to learn JavaScript and jQuery. Can you help me with an issue I am experiencing? Basically, I have a table and I need to identify which tr contains a td with the text "Weekly", "Daily", or "Monthly". Once I locate that specific t ...

Sorting a Javascript table performs effectively, however, the results may vary when iterating through all the indexes

I'm currently using a function to sort a table I have: function ReorderSupplyGP(table){ table.find('tr:not(.kn-table_summary)').sort(function (a, b) { var tda = $(a).find('td:eq(1)').text().trim(); var tdb = $(b).find(&a ...

Tips for transferring a boolean value to a generic parameter in Java?

Looking to pass a boolean value to the Generic type in order to be utilized within a condition. This is the generic type interface OptionTypeBase { [key: string]: any; } type OptionsType<OptionType extends OptionTypeBase> = ReadonlyArray<Opt ...

jqGrid and the use of prototype functions

When using prototype functions in my code, I encounter an issue where adding a select box to the jqgrid results in an extra option being added at the bottom with a value that is a function. However, when I remove the prototype functions, everything works a ...

While creating a React app, Docker becomes stuck due to a hangup when checking the core-js dependency

I've hit a roadblock in the build process. I'm working on an M1 Mac Mini and have attempted to build in both arm64 and x86_64 terminals, but the outcome is consistently the same. npm info lifecycle @babel/<a href="/cdn-cgi/l/email-protection" ...

Guide on Updating Data with PHP and MYSQL in Android Applications

For my app development, I am utilizing PHP MySQL to update data. Despite receiving the message "Update Data Successfully," upon checking my database, no changes are reflected in the values. Logcat shows: Log entries here... Here is the PHP Script used ...