Generate a model for JSON with attribute of the type List and String
up vote
0
down vote
favorite
thanks in advance to those who could see my publication. I'm working with services and I have the following JSON
"custom_attributes": [
{
"attribute_code": "meta_description",
"value": "Calzado"
},
{
"attribute_code": "category_ids",
"value": [
"2",
"151",
"161",
"163"
]
}
]
and what I try gives the following error if the Value attribute I place in a List.
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 8375 path $.custom_attributes[0].value
model
public class CustomAttribute {
@SerializedName("attribute_code")
private String attributeCode;
@SerializedName("value")
private List<String> value = null;
public String getAttributeCode() {
return attributeCode;
}
public void setAttributeCode(String attributeCode) {
this.attributeCode = attributeCode;
}
public List<String> getValue() {
return value;
}
public void setValue(List<String> value) {
this.value = value;
}
}
java android json gson
add a comment |
up vote
0
down vote
favorite
thanks in advance to those who could see my publication. I'm working with services and I have the following JSON
"custom_attributes": [
{
"attribute_code": "meta_description",
"value": "Calzado"
},
{
"attribute_code": "category_ids",
"value": [
"2",
"151",
"161",
"163"
]
}
]
and what I try gives the following error if the Value attribute I place in a List.
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 8375 path $.custom_attributes[0].value
model
public class CustomAttribute {
@SerializedName("attribute_code")
private String attributeCode;
@SerializedName("value")
private List<String> value = null;
public String getAttributeCode() {
return attributeCode;
}
public void setAttributeCode(String attributeCode) {
this.attributeCode = attributeCode;
}
public List<String> getValue() {
return value;
}
public void setValue(List<String> value) {
this.value = value;
}
}
java android json gson
What library are you using for converting JSON into POJOs?
– CROSP
Nov 9 at 22:48
I'm working with retrofit2
– dbenitobaldeon
Nov 9 at 22:51
Retrofit allows you to set different converters, e.gGSON
,Jackson
– CROSP
Nov 9 at 22:54
Please provide your model class as well, it seems you trying to parse list of strings instead of custom object
– CROSP
Nov 9 at 22:54
I do not know how to create a model class for this JSON, that's why my query is published. @CROSP , well I have the model like that and it gives me that error
– dbenitobaldeon
Nov 9 at 23:04
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
thanks in advance to those who could see my publication. I'm working with services and I have the following JSON
"custom_attributes": [
{
"attribute_code": "meta_description",
"value": "Calzado"
},
{
"attribute_code": "category_ids",
"value": [
"2",
"151",
"161",
"163"
]
}
]
and what I try gives the following error if the Value attribute I place in a List.
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 8375 path $.custom_attributes[0].value
model
public class CustomAttribute {
@SerializedName("attribute_code")
private String attributeCode;
@SerializedName("value")
private List<String> value = null;
public String getAttributeCode() {
return attributeCode;
}
public void setAttributeCode(String attributeCode) {
this.attributeCode = attributeCode;
}
public List<String> getValue() {
return value;
}
public void setValue(List<String> value) {
this.value = value;
}
}
java android json gson
thanks in advance to those who could see my publication. I'm working with services and I have the following JSON
"custom_attributes": [
{
"attribute_code": "meta_description",
"value": "Calzado"
},
{
"attribute_code": "category_ids",
"value": [
"2",
"151",
"161",
"163"
]
}
]
and what I try gives the following error if the Value attribute I place in a List.
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 8375 path $.custom_attributes[0].value
model
public class CustomAttribute {
@SerializedName("attribute_code")
private String attributeCode;
@SerializedName("value")
private List<String> value = null;
public String getAttributeCode() {
return attributeCode;
}
public void setAttributeCode(String attributeCode) {
this.attributeCode = attributeCode;
}
public List<String> getValue() {
return value;
}
public void setValue(List<String> value) {
this.value = value;
}
}
java android json gson
java android json gson
edited Nov 9 at 23:50
cricket_007
78.5k1142109
78.5k1142109
asked Nov 9 at 22:43
dbenitobaldeon
298
298
What library are you using for converting JSON into POJOs?
– CROSP
Nov 9 at 22:48
I'm working with retrofit2
– dbenitobaldeon
Nov 9 at 22:51
Retrofit allows you to set different converters, e.gGSON
,Jackson
– CROSP
Nov 9 at 22:54
Please provide your model class as well, it seems you trying to parse list of strings instead of custom object
– CROSP
Nov 9 at 22:54
I do not know how to create a model class for this JSON, that's why my query is published. @CROSP , well I have the model like that and it gives me that error
– dbenitobaldeon
Nov 9 at 23:04
add a comment |
What library are you using for converting JSON into POJOs?
– CROSP
Nov 9 at 22:48
I'm working with retrofit2
– dbenitobaldeon
Nov 9 at 22:51
Retrofit allows you to set different converters, e.gGSON
,Jackson
– CROSP
Nov 9 at 22:54
Please provide your model class as well, it seems you trying to parse list of strings instead of custom object
– CROSP
Nov 9 at 22:54
I do not know how to create a model class for this JSON, that's why my query is published. @CROSP , well I have the model like that and it gives me that error
– dbenitobaldeon
Nov 9 at 23:04
What library are you using for converting JSON into POJOs?
– CROSP
Nov 9 at 22:48
What library are you using for converting JSON into POJOs?
– CROSP
Nov 9 at 22:48
I'm working with retrofit2
– dbenitobaldeon
Nov 9 at 22:51
I'm working with retrofit2
– dbenitobaldeon
Nov 9 at 22:51
Retrofit allows you to set different converters, e.g
GSON
, Jackson
– CROSP
Nov 9 at 22:54
Retrofit allows you to set different converters, e.g
GSON
, Jackson
– CROSP
Nov 9 at 22:54
Please provide your model class as well, it seems you trying to parse list of strings instead of custom object
– CROSP
Nov 9 at 22:54
Please provide your model class as well, it seems you trying to parse list of strings instead of custom object
– CROSP
Nov 9 at 22:54
I do not know how to create a model class for this JSON, that's why my query is published. @CROSP , well I have the model like that and it gives me that error
– dbenitobaldeon
Nov 9 at 23:04
I do not know how to create a model class for this JSON, that's why my query is published. @CROSP , well I have the model like that and it gives me that error
– dbenitobaldeon
Nov 9 at 23:04
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
"custom_attributes"
itself is an array with objects
I assume somewhere you have List<CustomAttibute>
and that array has no consistent object format within. value
is both a String, and a List<String>
.
The best you can do is private Object value = null;
, then you must check its type and cast it later at runtime, or you can not use Retrofit w/ the Gson converter, as Gson expects consistently formed object types within lists (meaning for every JSON key, there is only one value type).
1
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
add a comment |
up vote
0
down vote
The error you are getting means that you are telling the model to expect an array where it should be getting a string.
In order to solve your issue easily you can use this online resource to generate your model (by just copy pasting the json file)
or you can use this plugin to generate you model directly from android studio!
Hope you got your answer!
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234206%2fgenerate-a-model-for-json-with-attribute-of-the-type-list-and-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
"custom_attributes"
itself is an array with objects
I assume somewhere you have List<CustomAttibute>
and that array has no consistent object format within. value
is both a String, and a List<String>
.
The best you can do is private Object value = null;
, then you must check its type and cast it later at runtime, or you can not use Retrofit w/ the Gson converter, as Gson expects consistently formed object types within lists (meaning for every JSON key, there is only one value type).
1
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
add a comment |
up vote
1
down vote
"custom_attributes"
itself is an array with objects
I assume somewhere you have List<CustomAttibute>
and that array has no consistent object format within. value
is both a String, and a List<String>
.
The best you can do is private Object value = null;
, then you must check its type and cast it later at runtime, or you can not use Retrofit w/ the Gson converter, as Gson expects consistently formed object types within lists (meaning for every JSON key, there is only one value type).
1
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
add a comment |
up vote
1
down vote
up vote
1
down vote
"custom_attributes"
itself is an array with objects
I assume somewhere you have List<CustomAttibute>
and that array has no consistent object format within. value
is both a String, and a List<String>
.
The best you can do is private Object value = null;
, then you must check its type and cast it later at runtime, or you can not use Retrofit w/ the Gson converter, as Gson expects consistently formed object types within lists (meaning for every JSON key, there is only one value type).
"custom_attributes"
itself is an array with objects
I assume somewhere you have List<CustomAttibute>
and that array has no consistent object format within. value
is both a String, and a List<String>
.
The best you can do is private Object value = null;
, then you must check its type and cast it later at runtime, or you can not use Retrofit w/ the Gson converter, as Gson expects consistently formed object types within lists (meaning for every JSON key, there is only one value type).
answered Nov 9 at 23:49
cricket_007
78.5k1142109
78.5k1142109
1
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
add a comment |
1
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
1
1
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
Thank you ! I was not sure about doing it that way, but I guess I should have tried before, anyway I got the result
– dbenitobaldeon
Nov 10 at 0:01
add a comment |
up vote
0
down vote
The error you are getting means that you are telling the model to expect an array where it should be getting a string.
In order to solve your issue easily you can use this online resource to generate your model (by just copy pasting the json file)
or you can use this plugin to generate you model directly from android studio!
Hope you got your answer!
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
add a comment |
up vote
0
down vote
The error you are getting means that you are telling the model to expect an array where it should be getting a string.
In order to solve your issue easily you can use this online resource to generate your model (by just copy pasting the json file)
or you can use this plugin to generate you model directly from android studio!
Hope you got your answer!
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
add a comment |
up vote
0
down vote
up vote
0
down vote
The error you are getting means that you are telling the model to expect an array where it should be getting a string.
In order to solve your issue easily you can use this online resource to generate your model (by just copy pasting the json file)
or you can use this plugin to generate you model directly from android studio!
Hope you got your answer!
The error you are getting means that you are telling the model to expect an array where it should be getting a string.
In order to solve your issue easily you can use this online resource to generate your model (by just copy pasting the json file)
or you can use this plugin to generate you model directly from android studio!
Hope you got your answer!
answered Nov 9 at 23:39
Georgios S.
1799
1799
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
add a comment |
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
can you see that the attribute value receives first a string data then a list, how to make a model for that?, is my question.
– dbenitobaldeon
Nov 9 at 23:49
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
please post the entire json or use the online tool and it will produce the model for you!
– Georgios S.
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
@GeorgiosS. The JSON is in the question...
– cricket_007
Nov 9 at 23:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234206%2fgenerate-a-model-for-json-with-attribute-of-the-type-list-and-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What library are you using for converting JSON into POJOs?
– CROSP
Nov 9 at 22:48
I'm working with retrofit2
– dbenitobaldeon
Nov 9 at 22:51
Retrofit allows you to set different converters, e.g
GSON
,Jackson
– CROSP
Nov 9 at 22:54
Please provide your model class as well, it seems you trying to parse list of strings instead of custom object
– CROSP
Nov 9 at 22:54
I do not know how to create a model class for this JSON, that's why my query is published. @CROSP , well I have the model like that and it gives me that error
– dbenitobaldeon
Nov 9 at 23:04