Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:27:08+00:00 2026-06-12T22:27:08+00:00

given JSON {news : [ {…}, {…}, {…} ] } the array contains custom

  • 0

given JSON

{"news" : [ {...}, {...}, {...} ] }

the array contains custom objects, which I already declared as POJOs. Want I simply want to map my custom objects by keypath “news”.

restTemplate.exchange(URI + "/news/{limit}/", HttpMethod.GET, CustomObject[].class, 10)

throws an exception, because this JSON is expected

[ {...}, {...}, {...}]

Is there a way to configure RestTemplate to match my needs?

Regards

Update:

restTemplate.exchange(URI + "/news/{limit}/", HttpMethod.GET, requestEntity, JsonElement.class,10).getBody().getAsJsonObject().get("news");
CustomObject[] result = gson.fromJson(body, CustomObject[].class);

This snippet works but is there a cleaner way? For my suprise mapping to JSONObject doesn’t even worked, JSONElement did the job at the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:27:11+00:00Added an answer on June 12, 2026 at 10:27 pm

    Well I’ll add my update in here to close this question. If someone can provide a cleaner solution I’ll be happy to accept it:

    restTemplate.exchange(URI + "/news/{limit}/", HttpMethod.GET, requestEntity, JsonElement.class,10).getBody().getAsJsonObject().get("news");
    CustomObject[] result = gson.fromJson(body, CustomObject[].class);
    

    This snippet works but is there a cleaner way? For my suprise mapping to JSONObject doesn’t even worked, JSONElement did the job at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following array of json objects: var items = [ {id:1, parentId:0, name:'item1'},
Is there a tool that generates the JSON objects in Java when given JSON
I have some json data given below and I want to display it in
Given a json array: [{ x:5, y:20 },{ x:6, y:10 },{ x:50, y:5 }]
I have some JSON data given below and I want to display it in
Given the following JSON data: [ { pk: 2, model: corkboard.announcement, fields: { body:
i need to parse the JSON data given below. {result:[{bookId:142645,bookpb:MF, bookTs:1328999630000,clipStatus:D,bookDetail:{arrival:1,purchase:1,sold:1}, hierarchies:{categories:[4],events:[]},shopId:769752}, upto sold
I ve data in the JSON format given below,need to populate the slick grid
Given a stream of JSON, how can I read it as XML. I am
Given a certain date, I want to set the value of a cell with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.