0

having a bit of an issue deserializing from this GET call using moshi

https://min-api.cryptocompare.com/data/pricemultifull?fsyms=007,1337&tsyms=EUR,USD result looks like this.

{
   "RAW":{
     //not used 
},
"DISPLAY":{
  "1337":{
     "EUR":{
    "FROMSYMBOL":"1337",
    "TOSYMBOL":"€",
     "MARKET":"CryptoCompare Index",
    "PRICE":"€ 0.0001115",
    "LASTUPDATE":"Just now",
    "LASTVOLUME":"1337 0",
    "LASTVOLUMETO":"€ 0",
    "LASTTRADEID":0,
    "VOLUMEDAY":"1337 0",
    "VOLUMEDAYTO":"€ 0",
    "VOLUME24HOUR":"1337 0",
    "VOLUME24HOURTO":"€ 0",
    "OPENDAY":"€ 0.0001018",
    "HIGHDAY":"€ 0.0001115",
    "LOWDAY":"€ 0.0001018",
    "OPEN24HOUR":"€ 0.0001115",
    "HIGH24HOUR":"€ 0.0001115",
    "LOW24HOUR":"€ 0.0001018",
    "LASTMARKET":"Yobit",
    "CHANGE24HOUR":"€ 0.0",
    "CHANGEPCT24HOUR":"0.00",
    "CHANGEDAY":"€ 0.0000097",
    "CHANGEPCTDAY":"9.52",
    "SUPPLY":"1337 28,988,904,177.4",
    "MKTCAP":"€ 3,232.91 K",
    "TOTALVOLUME24H":"1337 1,360.28 K",
    "TOTALVOLUME24HTO":"€ 151.70"
     },
      "USD":{
      "FROMSYMBOL":"1337",
    "TOSYMBOL":"$",
    "MARKET":"CryptoCompare Index",
    "PRICE":"$ 0.0001490",
    "LASTUPDATE":"4 hours ago",
    "LASTVOLUME":"1337 12,553.1",
    "LASTVOLUMETO":"$ 1.87",
    "LASTTRADEID":"200003428",
    "VOLUMEDAY":"1337 19,183.0",
    "VOLUMEDAYTO":"$ 2.81",
    "VOLUME24HOUR":"1337 28,256.0",
    "VOLUME24HOURTO":"$ 3.95",
    "OPENDAY":"$ 0.0001250",
    "HIGHDAY":"$ 0.0001490",
    "LOWDAY":"$ 0.0001250",
    "OPEN24HOUR":"$ 0.0001250",
    "HIGH24HOUR":"$ 0.0001490",
    "LOW24HOUR":"$ 0.0001250",
    "LASTMARKET":"Yobit",
    "CHANGE24HOUR":"$ 0.000024",
    "CHANGEPCT24HOUR":"19.20",
    "CHANGEDAY":"$ 0.000024",
    "CHANGEPCTDAY":"19.20",
    "SUPPLY":"1337 28,988,904,177.4",
    "MKTCAP":"$ 4,319.35 K",
    "TOTALVOLUME24H":"1337 1,360.28 K",
    "TOTALVOLUME24HTO":"$ 202.43"
 }
 },
 "007":{
 "EUR":{
    "FROMSYMBOL":"007",
    "TOSYMBOL":"€",
    "MARKET":"CryptoCompare Index",
    "PRICE":"€ 1.08",
    "LASTUPDATE":"Just now",
    "LASTVOLUME":"007 0",
    "LASTVOLUMETO":"€ 0",
    "LASTTRADEID":0,
    "VOLUMEDAY":"007 0",
    "VOLUMEDAYTO":"€ 0",
    "VOLUME24HOUR":"007 0",
    "VOLUME24HOURTO":"€ 0",
    "OPENDAY":"€ 1.08",
    "HIGHDAY":"€ 1.08",
    "LOWDAY":"€ 1.08",
    "OPEN24HOUR":"€ 1.08",
    "HIGH24HOUR":"€ 1.08",
    "LOW24HOUR":"€ 1.08",
    "LASTMARKET":"Yobit",
    "CHANGE24HOUR":"€ 0.0",
    "CHANGEPCT24HOUR":"0.00",
    "CHANGEDAY":"€ -0.00013",
    "CHANGEPCTDAY":"-0.01",
    "SUPPLY":"007 0",
    "MKTCAP":"€ 0",
    "TOTALVOLUME24H":"007 0",
    "TOTALVOLUME24HTO":"€ 0"
 },
     "USD":{
    "FROMSYMBOL":"007",
    "TOSYMBOL":"$",
    "MARKET":"CryptoCompare Index",
    "PRICE":"$ 6.51",
    "LASTUPDATE":"4 months ago",
    "LASTVOLUME":"007 0.01536",
    "LASTVOLUMETO":"$ 0.1000",
    "LASTTRADEID":"182056756",
    "VOLUMEDAY":"007 0",
    "VOLUMEDAYTO":"$ 0",
    "VOLUME24HOUR":"007 0",
    "VOLUME24HOURTO":"$ 0",
    "OPENDAY":"$ 6.51",
    "HIGHDAY":"$ 6.51",
    "LOWDAY":"$ 6.51",
    "OPEN24HOUR":"$ 6.51",
    "HIGH24HOUR":"$ 6.51",
    "LOW24HOUR":"$ 6.51",
    "LASTMARKET":"Yobit",
    "CHANGE24HOUR":"$ 0.0",
    "CHANGEPCT24HOUR":"0.00",
    "CHANGEDAY":"$ -0.00034",
    "CHANGEPCTDAY":"-0.01",
    "SUPPLY":"007 0",
    "MKTCAP":"$ 0",
    "TOTALVOLUME24H":"007 0",
    "TOTALVOLUME24HTO":"$ 0"
   }
  }
 }
}

getting the following error.

com.squareup.moshi.JsonDataException: Required value 'displayMapToCurrency' 
missing at $.DISPLAY.1337

im using the following data classes one wrapping the other

//outer class

data class FullPriceWrapper(
@Json( name = "DISPLAY")
val DISPLAY : Map<String, FullPriceWrapperInternalDisplay>
)

//intermediate class

data class FullPriceWrapperInternalDisplay(
   val displayMapToCurrency : Map<String,CurrencyFullPriceDataDisplay>
)

//inner most class

data class CurrencyFullPriceDataDisplay(
@Json(name = "FROMSYMBOL")
val FROMSYMBOL: String,
@Json(name = "TOSYMBOL")
val TOSYMBOL: String,
@Json(name = "MARKET")
val MARKET: String)

so I'm presuming the intermediate class isn't being instantiated here from the error message? Is there an issue in moshi with nested classes? I create my api instance with retrofit like below passing in MoshiConverterFactory.

return Retrofit.Builder()
            .baseUrl(compareApiEndPoint)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .build().create(CryptoApi::class.java)

I've also tried the code generation annotation to create adapters for me on each class but with no joy. the adapters are generated. maybe Ive got the wrong idea but i thought these were auto-generated with the annotation? (shown below)

@JsonClass(generateAdapter = true)

But I think I am not familiar enough with the library at present. I am wondering if I need to add a custom adapter like I've seen in other examples? I've also tried this but i'm not sure how to create these adapters from the examples I've seen? If anyone has an ideas on how to rectify this error that would be great! Also I hope the question was relatively precise. Thanks!

filthy_wizard
  • 740
  • 11
  • 25
  • 1
    there is no key in your json with the name "displayMapToCurrency." looks like your models are expecting an extra json object that doesn't exist. you might mean to have `val DISPLAY : Map>`. – Eric Cochran Jun 01 '18 at 07:00
  • yeah, the format of the json is a nested map. i just added a @FromJson annotated method in a custom adapter with JsonReader passed as a param and managed to get it working – filthy_wizard Jun 02 '18 at 22:09

0 Answers0