1

I am using Angular 2 to send the following JSON to a Spring Boot controller:

{
  "portal_name": "test",
  "app_name": "test",
  "app_owner": "test",
  "app_submitter": "test",
  "onboarding_form_blob": [
    {
      "newSplunkRow": "test"
    }
  ]
}

But when I send the JSON I get an this error from the Spring controller:

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Can not deserialize instance of java.lang.String out of START_ARRAY token

This is what the controller looks like for the Blob:

@Column(name = "onboarding_form_blob")
private String onboarding_form_blob;

And these are the Getters and Setters:

public String getOnboarding_form_blob() {
            return onboarding_form_blob;
        }

public void setOnboarding_form_blob(String onboarding_form_blob) {
            this.onboarding_form_blob = onboarding_form_blob;
        }
6
  • Related/possible duplicate stackoverflow.com/questions/37471005/… Commented Jun 5, 2017 at 17:10
  • nope. I read through this and its not related. Commented Jun 5, 2017 at 17:53
  • 1
    Try private java.util.List onboarding_form_blob;. Adjust the getters and setters. The error is referring mismatch between array type and string. Commented Jun 7, 2017 at 2:26
  • can you post the complete code of your controller? Commented Jun 8, 2017 at 19:01
  • Are you sure the problem is on the server side? Did you try to to send the same JSON with a different method (eg.: with Postman)? Commented Jun 9, 2017 at 12:41

4 Answers 4

2

Your JSON payload is clear to me: JSON payload

Not completely sure what your controller looks like. It'll be helpful if you provide the complete signature of the method in the controller and the complete Blob class. But I'm now guessing it looks something like this?

My best guess

If so: Then @Veeram is right. The issue is that the getters and setters for newSplunkRow expect a String, and you're sending an Array with one object instead of that String.

You can fix it by either changing the controller or by changing the JSON you're sending to match the controller. What's best depends on the data you're trying to send and what you want to do with it once received. (From your @Column annotation I guess you're going to store it in the database? What do your tables look like?)

Sign up to request clarification or add additional context in comments.

Comments

0

In your request body, onboarding_form_blob field is an array, but in your POJO (which assuming is expected request body type in your controller) onboarding_form_blob is not of Collection type. so you have two options:

1.change onboarding_form_blob type in POJO to List, like this:

@Column(name = "onboarding_form_blob")
private List<String> onboarding_form_blob;

public List<String> getOnboarding_form_blob() {
            return onboarding_form_blob;
}

public void setOnboarding_form_blob(List<String> onboarding_form_blob) {
            this.onboarding_form_blob = onboarding_form_blob;
}

and change your JSON payload to string array:

"onboarding_form_blob": [
"{\"newSplunkRow\": \"test\"}",
"{\"newSplunkRow2\": \"test2\"}"
]

2. keep your current POJO but modify your JSON payload so it looks like a string, like this:

{
  "portal_name": "test",
  "app_name": "test",
  "app_owner": "test",
  "app_submitter": "test",
  "onboarding_form_blob": "[{\"newSplunkRow\": \"test\"}]"
}

Note the escaped double qoutes in JSON payload's onboarding_form_blob field

Comments

0

I'm sure you realise that JSON is a text protocol and a BLOB is a binary object, in order to store any binary object in JSON notation you will have to translate the BLOB to a base64 encoded string, this will take care of any characters that could upset the JSON protocol.

Comments

0

With this you declare the onboarding_form_blob as String (btw. a bit misleading name, cause blob means binary large object in database terminology):

@Column(name = "onboarding_form_blob")
private String onboarding_form_blob;

Like this you send JSON Objects:

 "onboarding_form_blob": [
    {
      "newSplunkRow": "test"
    }
  ]

In fact the parser thinks this structure should be an array.

This is clearly a misunderstanidng of the json format. If you declare a String, send a String:

 "onboarding_form_blob": "[\r\n    {\r\n      \"newSplunkRow\": \"test\"\r\n    }\r\n  ]"

Comments

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.