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 8651745
In Process

The Archive Base Latest Questions

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

I have a standard Spring Roo project that I’m trying to use as a

  • 0

I have a standard Spring Roo project that I’m trying to use as a REST API to a database, using Web MVC and the automatically-generated JSON controllers. I’m trying to send a POST request to create an object via either form data or JSON (preferably JSON), but I’m receiving fairly strange behaviour.

My hierarchical entity has an optional reference to itself as a parent. It looks like this:

public class LandType {
    private String name;
    private String description;

    @ManyToOne
    private LandType parent;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
    private Set<LandType> children = new HashSet<LandType>();

    @ManyToMany(cascade = CascadeType.ALL)
    private Set<Param> params = new HashSet<Param>();
}

When I try to create a new instance via a JSON POST request without a value for parent (with just name and description), it works. When I try to create it with a parent value (I use the parent ID as an integer, since that’s what the stock Roo form does), I get the Spring error:

java.lang.Integer cannot be cast to java.util.Map

I don’t know what it’s doing trying to convert anything to a map, and following it through with a debugger makes little sense. It goes in via the controller, into fromJsonToLandType, then tries to deserialise and eventually throws the exception:

flexjson.factories.BeanObjectFactory.instantiate(BeanObjectFactory.java:17)
flexjson.ObjectBinder.bind(ObjectBinder.java:86)
flexjson.ObjectBinder.bindIntoObject(ObjectBinder.java:139)
flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:38)
flexjson.ObjectBinder.bind(ObjectBinder.java:86)
flexjson.ObjectBinder.bind(ObjectBinder.java:65)
flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:158)
...

The same kind of thing happens when I try to pass in an array of parameters as {…, ‘params’: [10, 11]}. It seems like Spring Roo doesn’t quite know how to handle JSON inputs for non-primitive types, or I don’t know what format to provide them in. What am I doing wrong here?

Edit

I’m mainly testing this with curl to control exactly what goes in. An example call would be:

> curl -i -X POST -H "Content-type: application/json" -d "{'name':'test', 'description': 'test', 'parent': 8}" http://localhost:8080/mutopia-server/landtypes

… where 8 is the ID of an existing LandType, and again, removing parent makes it work. Strangely enough, I’ve got the call working for standard form data via the standard Roo controller (replace -H "Content-type: application/json" with -H "Accept: text/html"), so it’s not as urgent an issue, but eventually I’ll need a fully-operational JSON REST API. Adding Accept: application/json doesn’t help either, since the JSON controller is by this point being called, but something funky is going on inside.

  • 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-12T14:08:46+00:00Added an answer on June 12, 2026 at 2:08 pm

    So the reason is that Flexjson (the deserialiser) is expecting a set (or JSON array) or Param objects (in JSON object form), but instead it finds an array of integers. Since Flexjson doesn’t know anything about Spring or Roo, it doesn’t recognise the integers as IDs and look them up with the appropriate Finder as I had naively hoped it would.

    The solution seems to be to manually parse out these kinds of ID references in the controller before calling the JSONDeserializer.deserialize(). Perhaps one day this could become a feature of the @RooJson addon (related issue), but not yet.

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

Sidebar

Related Questions

A standard spring web application (created by Roo or Spring MVC Project Template) create
I am playing around and converting an Spring MVC REST project to use Jersey,
I have a pretty standard project with Spring Security. I have a login form
I have a standard Maven webapp structure defined, and it uses Spring MVC. I
I have a spring MVC application using JSP as my view technologies with Jquery
I have a fairly standard Spring/Hibernate Java project where I need to set a
Here's the scenario: I have a standard applicationConfig.xml spring configuration for a basic web
Here's the scenario: I have a standard applicationConfig.xml spring configuration for a basic web
I have a web application that's based on Spring and the application contexts, applicationContext.xml
I am using Spring MVC within Tomcat and what I thought was a standard

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.