1

I need to convert 2-D array comes from JSON to a string. I just need to manipulate that value.

There is an example of the JSON:

https://en.wikipedia.org/wiki/GeoJSON

@RequestMapping is the way to manipulate value that comes from REST. But i dont know how to do it for nested object.

    @ResponseBody
    public GeoJson saveData(@RequestParam {What i need}...) throws IOException{
        return geoJSONRepository.save(geoJson);
    }

GeoJson class:

@Entity
public class GeoJson {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    private String type;
    @OneToMany(cascade = CascadeType.ALL)
    @ToString.Exclude
    private List<Feature> features = new ArrayList<Feature>();
    public GeoJson() {
    }
}

Feature class:

@Entity
public class Feature {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long fId;
    private String type;
    @OneToOne(cascade = CascadeType.ALL)
    private Properties properties;
    @OneToOne(cascade = CascadeType.ALL)
    private Geometry geometry;
}

Properties class:

@Entity
public class Properties {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pId", nullable = false)
    private Long pId;
    @Column(name = "property_type")
    private String type;
}

Geometry class:

@Entity
public class Geometry {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "gId", nullable = false)
    private Long gId;
    private String type;
    private String coordinates; //2-d coordinates value

}
6
  • A questions, is your endpoint GET? Simply stating the object type after @RequestParam should work For parameter as big as GeoJSON, I would suggest using @RequestBody instead of @RequestParam Commented Mar 10, 2022 at 8:56
  • On second thought, possible duplicate of: stackoverflow.com/questions/16942193/… Commented Mar 10, 2022 at 9:00
  • @stark with @RequestBody How could i convert 2-D array to String? Should i create an data transfer object with 2-d array and assign posted JSON to it, then convert it to the entity that contains string coordinates? Commented Mar 10, 2022 at 9:05
  • Check the link to an already asked question. If you just specify they type as String geoJson it should automatically translate your incoming param to that String object Commented Mar 10, 2022 at 9:21
  • @stark i think you misunderstood. The link is not related to my question. I don't want to convert whole object to string. I want to just convert 2-d array to string in geometry class. Commented Mar 10, 2022 at 9:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.