We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public static void main(String[] args) throws JsonProcessingException { class User{ private String a; public User() { } public User(String a) { this.a = a; } @Override public String toString() { return "User{" + "a='" + a + '\'' + '}'; } public String getA() { return a; } public void setA(String a) { this.a = a; } } ArrayList<Object> users = Lists.newArrayList(new User("a"), new User("b")); Gson gson = new GsonBuilder().create(); String s = gson.toJson(new User("c")); String s1 = (new ObjectMapper()).writeValueAsString(users); System.out.println("s = " + s); System.out.println("s1 = " + s1); }
//return : s = null s1 = [{"a":"a"},{"a":"b"}]
The text was updated successfully, but these errors were encountered:
gson version : 2.8.6
Sorry, something went wrong.
Local classes are not supported. See #1510 and https://github.com/google/gson/blob/master/UserGuide.md#finer-points-with-objects. To solve this make User either a top-level class or a static nested class.
User
static
(comment copied from lyubomyr-shaydariv's comment here)
No branches or pull requests
//return :
s = null
s1 = [{"a":"a"},{"a":"b"}]
The text was updated successfully, but these errors were encountered: