Is it possible to create a mapping for the jsonProperty of nested fields in an object?

In my project, I have created two classes named Car.java and Bus.java.

        Car.java   
        private Property property;
       Bus.java
       private Property property;

The Property.java class contains attributes for number and colour.

        Property.java
        private String number;
        private String colour;

I need the properties field to be named differently based on whether it is called from Car.java or Bus.java. For example, carNumber, carColour, busNumber, busColour in the output JSON.

Is there a way to achieve this using a single Property class? The desired output JSON structure should be: "Car":{ "Property" : { "carNumber" : "num", "carColor" : "blue" } }

Answer №1

Indeed, it is possible to employ the @JsonUnwrapped annotation along with the prefix attribute.

// ExampleClass.java

@JsonUnwrapped(prefix="example-")
private Property property;

As a result of serialization, the JSON output will appear as follows:

{ "example-name": "example name", "example-number" : "example number" }

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

Exploring the power of simplejson in Python by parsing JSON data

After sending a URL request with urllib2, I am struggling to read JSON data. Here is my code: request = urllib2.Request("https://127.0.0.1:443/myAPI", data=form_data, headers=headers) response = urllib2.open(request) The issue arises when attempting to p ...

Leveraging jQuery or javascript to display json data in a table with multiple columns

My goal is to convert a JSON data into an HTML table that dynamically creates columns based on the content of the JSON. However, I am facing challenges in looping through the JSON and rendering multiple columns when necessary. The desired output for the e ...

What is the best way to add custom styles to an Ext JS 'tabpanel' xtype using the 'style

Is there a way to change the style of a Ext.tab.Panel element using inline CSS structure like how it's done for a xtype: button element? { xtype: "button", itemId: "imageUploadButton1", text: "Uploader", style: { background : ' ...

Selenium scripts are unable to maximize the browser when running in the background

I am facing an issue with maximizing the selenium code when running the script in the background. The maximum window size specified is 1036 by 780 pixels. How can I maximize the browser window in the background? ...

Assistance needed with sending JSON data to a PHP server using the POST method

I am attempting to transfer JSON data from an HTML form to a PHP server using the POST method. The issue I am encountering is that my code always ends up in the fail block within the callback function. Despite this, the Firebug console (ctrl+shift+J) does ...

Is there a way to adjust the typing speed of the Chrome driver in Selenium?

I'm working on a UI test that utilizes the Selenium Chrome driver. I would like to adjust the form filling speed to be slower, but my attempts to find a solution through Google have been unsuccessful. Does anyone happen to know how this can be accomp ...

Checking the Json response with Java

Can someone help me extract the textType and taxAmount values from the JSON response below? { "taxExempt": false, "billingAddress": { "addressLine1": "Millers Rd", "addressLine2": "", "city": "Bengaluru", "postalCode": "560052", "sta ...

Achieving JSON element sorting in the most effective way

https://i.stack.imgur.com/NQbdN.png Each array contains the following information: {{ id: 39, treaty_number: "qwe", insurant_name: "222", belonging_to_the_holding_company: "test", date_start: "2016-04-15", etc }} Is there a way to sort each array in asc ...

Using Ajax (Jquery) to send data to a PHP script

Currently, I am working on an application where users can click a checkmark to complete a task. When this action is taken, a popup window appears (created using bootstrap), prompting the user to enter their hours worked on the task. After entering the hour ...

What is the method for inputting multi-line strings in the REST Client extension for Visual Studio Code?

Clarification There seems to be some confusion regarding the nature of the data I am storing. I am developing a code snippet web application using Express.js and MongoDB. The purpose is not to store executable code for later use; instead, I am saving snipp ...

Encountering a HttpMediaTypeNotAcceptableException while making a jQuery ajax request after upgrading to Spring 3.2.4版本

Whenever I attempt to execute a jQuery ajax call, I am facing the HttpMediaTypeNotAcceptableException. The current configuration that I have includes: Within the context (which is in the classpath), I have the following: <context:component-scan base- ...

What is the best way to extract JSON data from a couchDB database and interpret it in Xcode?

Let's say I have a record stored in my CouchDB with fields "password" and "username". The URL for this specific document is: My goal is to extract the values of these fields from the CouchDB document and process them in Xcode. I attempted to use http ...

Retrieving the data payload from a 400 response using HttpURLConnection

When making a JSON request to my web service, I return a 400 message code with a detailed JSON error response if the request is bad. But how can I retrieve this payload on the client side using HttpURLConnection? The connection's InputStream is null a ...

Changing a nested JSON array into a Java array

I need assistance in converting this JSON Array into a Java class Type array for Android. The goal is to extract all elements from the array, including the "doses" array, and create a Java array. [ { "_id":"58299a0ae1053c391fb95026", ...

Tips for transforming an html form into an ajax request for a rest controller when dealing with a multi-select field

I am encountering an issue with the field "roles" as it is a select list with multiple choices. I need to convert this field into an array, but I have not been able to find any information on how to do so. Any assistance would be greatly appreciated. Thi ...

Guide to creating a locator in Selenium Webdriver and Java to trigger a click on an image

I am trying to automate clicking on an image using an anchor tag in Selenium Webdriver with Java. <a title="Complete Step" class="tableIcon" href="javascript:__doPostBack('__Page','COMPLETEJS_2309234_2_2_0')"> <img title="Co ...

Issues with Retrieving Data from Microsoft Dynamics 365 CRM

As of late, I've been given the task of automating MS CRM 365 using Selenium Automation. I've decided to utilize Gradle and Java for this project within IntelliJ. However, a major hurdle I'm facing is the inability to access elements on a f ...

Understanding JSON Parsing in iOS devices

I have received this JSON data for currency exchange rates: {"Curs":[{"ID":"AED","Name":"Dirhamul Emiratelor Arabe","Curs":"0.8013","Multiplier":"1","Data":"2011-03-21"},{"ID":"AUD","Name":"Dolarul australian","Curs":"2.9611","Multiplier":"1","Data":"2011- ...

Change a JSON file of Firefox bookmarks into markdown format

Context I'm looking to display a selection of my bookmarks on my Hugo website, sourced from Firefox in JSON format. I want the output to reflect the nested structure through a nested list, tree view, or accordion format. The content on my website is ...

Copy both the image and JSON object to the clipboard

I am attempting to utilize the clipboard API to write an image and JSON object to the window clipboard. I am working with Vue and Electron and have successfully written an image and plain text, but I encounter an error when trying to write a JSON object: ...