1

trying to call a rest endpoint which returns a simple json but i fail all the time.

The Result looks like that:

{
  "Products": [
    {
      "Name": "ABC",
      "Guid": "4711"
    },
    {
      "Name": "DEF",
      "Guid": "9876"
    },
    {
      "Name": "HGT",
      "Guid": "159"
    }
  ]
}

My Code like that:

override fun getProductMetaList(): List<BestProductMetaInfo> {
    val url = "https://$baseUrl/api/meta"
    return this.getForObject(url, GetProductMetaListResult::class.java)?.Products ?: emptyList()
}

...

@JsonIgnoreProperties(ignoreUnknown = true)
data class GetProductMetaListResult(
        @JsonProperty("Products")
        var Products: List<ProductMetaInfo> = emptyList()
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class ProductMetaInfo(
        @JsonProperty("Guid")
        var Guid: String = "",
        @JsonProperty("Name")
        var Name: String = ""
)

And the result always:

nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of GetProductMetaListResult (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value

I tried using default values and nullable value, but everything results the same.

IEE1394
  • 1,181
  • 13
  • 33
  • Which _jackson_ version you're using and did you checked this : https://stackoverflow.com/questions/45110371/no-string-argument-constructor-factory-method-to-deserialize-from-string-value – Vivek Mar 18 '19 at 20:51
  • hm i use the spring boot 2.1.3 delivered jackson – IEE1394 Mar 18 '19 at 21:01
  • 1
    It looks like your api response is coming as String but not well formed json ? Did you try to consume the api using postman & check result ? What is the `accept` header tag: `application/json` ? – Amith Kumar Mar 19 '19 at 04:53

1 Answers1

0

As Your API response is started with {, It's a JSON object. But you are trying to convert it as List as a result Exception occured.

First Parse it as JSON object and then get list from its result.

Simeon Leyzerzon
  • 18,658
  • 9
  • 54
  • 82
Anisuzzaman Babla
  • 6,510
  • 7
  • 36
  • 53