Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have this JSON example
{ "name": "custom_text" }
My Object look like
public class NameObj {
private String name;
}
And with readValue() method from Jackson can deserialized my json into NameObj.
The real problem is when i don't have "name"
{ [ "custom_text" ] }
How create object in this case? And deserialization is same?
In the example { "names" : [ "custom_text" ] } it does not really
matter if you represent the [ "custom_text" ] as list or array but if
you choose the latter, it would rather be String[] instead of Array[].
Also mind the type erasure if you choose List String . Then you have
to use e.g. TypeReference helpers.
Answer by mle
List String work for me. Thank you mle
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
I am trying to pass a string extracted from an API response in a subsequent call in JMeter. I am able to extract the object I want ("thing": "THING"), store it as variable $thisThing and then pass it, but not as a string.
Using this as my body data:
{
"foo": "bar",
"thing": ${thisThing}
}
...results in this request body:
{
"foo": "bar",
"thing": THING,
}
And the API errors out, unexpected token. Looking into post-processing solutions but I can't dig up anything of relevance.
As per JSON Object Literals:
Keys must be strings, and values must be a valid JSON data type:
string
number
object
array
boolean
null
so if this THING supposed to be a JSON String - you need to surround it with quotation marks:
{
"foo": "bar",
"thing": "${thisThing}"
}
or amend your Post-Processor configuration to extract the THING value along with surrounding quotation marks.
You might also need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
String names = "Peter, John, Andy, David";
String [] splitNames = names.split(",");
System.out.println(Arrays.tostring(splitNames(','));
I am beginner and I am trying to correct the code to the end result of my question listed. I am teaching myself from a book which has no listed details. If someone could assist that would be great. Thank you! I think I am on the right path I am overlooking my mistake.
This is easier to accomplish with the Stream api that was introduced in Java 8:
System.out.println(
Arrays.stream(splitNames)
.collect(Collectors.joining(", ", "{", "}"))
);
Here's a good tutorial for Stream collectors: https://www.baeldung.com/java-8-collectors
Just correct this line:
System.out.println(Arrays.tostring(splitNames(','));
to:
System.out.println(Arrays.toString(splitNames));
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying modification of an instance's fields through Java reflection.
Here is my original code.
for(Field f: customerClass.getDeclaredFields()) {
System.out.println(f);
}
System.out.println("\n");
System.out.println(customerClass.getDeclaredField("firstName"));
for(int i=0; i < columnNames.length; i++) {
System.out.println(columnNames[i]);
field = customerClass.getDeclaredField(columnNames[i]);
field.setAccessible(true);
And the results.
private java.lang.String Customer.firstName
private java.lang.String Customer.lastName
private java.lang.String Customer.firstName
"firstName"
java.lang.NoSuchFieldException: "firstName"
at java.lang.Class.getDeclaredField(Class.java:2070)
I am wondering why "customerClass.getDeclaredField("firstName")" works, but "customerClass.getDeclaredField(columnNames[i])" throws an Exception, since columnNames[0] == "firstName".
If you'll look at your output for columnNames[0], you'll see that it's not firstName, it's "firstName". Remove the quotes and it should work.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
[
{
"firstName":"Ivan",
"lastName":"Petrov",
"birthDate":"1993-03-09",
"email":"kazakhsam",
"address":{
"country":"Russia",
"city":"Moscow",
"street":"Lenin",.
"buildingNo":"10"
}
}
]
It gives me this error:
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
Thanks in advance.
Your JSON is not valid. You have an extra dot character after "Lenin",.
Cou can validate you JSON String with online validators, I suggest you to use this one: https://jsonformatter.curiousconcept.com/
If you paste your JSON there then it tells excatly what is wrong with your json string:
Error:Strings should be wrapped in double quotes.[Code 17, Structure
34]
Error:Invalid characters found.[Code 18, Structure 34]
Use jsonlint.com to check for correct indentation.
This is a json array not json object try to parse array object.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
my code looks like this:
Student jackNapoli = new Student(3, Jack, Napoli, The_Lawyer99#yahoo.com, 19, 85,84,87);
I am trying to create an new object of the Student class. My problem is the # symbol in the email address. How do I get this to not show up as error?
The problem is not in the # symbol.
The way you are passing the parameters to Student, Jack, Napoli and The_Lawyer99#yahoo.com are seen as object.
The compiler might tell you the problem is with the # because it is reserved for annotation in java. However, the real problem is that you probably want to pass these values as string using quotes.
Student jackNapoli = new Student(3, "Jack", "Napoli", "The_Lawyer99#yahoo.com", 19, 85,84,87);