How avoid print, the ""@type":"com.company.Main$Foo"" ?
ilwsm opened this issue · comments
public static class Foo {
private final int id;
private final String name;
public int getId() {
return id;
}
public String getName() {
return name;
}
public Foo() {
name = null;
id = 0;
}
public Foo(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public String toString() {
return "Foo{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
@Test
public void whenSerializeAndDeserializeUsingJsonio_thenCorrect(){
Foo foo = new Foo(1,"first");
String jsonStr = JsonWriter.objectToJson(foo);
Foo result = (Foo) JsonReader.jsonToJava(jsonStr);
assertEquals(foo.getId(),result.getId());
}
String jsonStr = {"@type":"com.company.Main$Foo","id":1,"name":"first"}
How avoid print, the ""@type":"com.company.Main$Foo"" ?
See the User Guide for json-io:
https://github.com/jdereg/json-io/blob/master/user-guide.md
You will want to set the TYPE parameter to false and it will not emit @type.
CUSTOM_WRITER_MAP // Set to Map<Class, JsonWriter.JsonClassWriterEx> to
// override the default JSON output for a given class.
NOT_CUSTOM_WRITER_MAP // Set to Collection<Class> to indicate
classes that should
// not be written by a custom writer.
DATE_FORMAT // Set this format string to control the
format dates are
// written. Example: "yyyy/MM/dd HH:mm". Can also be a
// DateFormat instance. Can also be the constant
// JsonWriter.ISO_DATE_FORMAT or
// JsonWriter.ISO_DATE_TIME_FORMAT
TYPE // Set to boolean true to force all data types to be
// output, even where they could have been omitted. Set
// to false to prevent @type from being
written. Do not set
// in order to minimize the number of @type's emitted.
PRETTY_PRINT // Force nicely formatted JSON output
// (See http://jsoneditoronline.org for example format)
FIELD_SPECIFIERS // Set to a Map<Class, List<String>> which is used to
// control which fields of a class are output.
FIELD_NAME_BLACK_LIST // Set value to a Map<Class, List<String>>
which will be used
// to control which fields on a class are not
output. Black
// list always has priority to
FIELD_SPECIFIERS
ENUM_PUBLIC_ONLY // If set, indicates that private variables of
ENUMs are not
// serialized.
WRITE_LONGS_AS_STRINGS // If set, longs are written in quotes
(Javascript safe).
// JsonReader will automatically convert Strings back
// to longs. Any Number can be set from a String.
TYPE_NAME_MAP // If set, this map will be used when writing
@type values.
// Allows short-hand abbreviations for type names.
SHORT_META_KEYS // If set, then @type => @t, @keys => @k, @Items => @e,
// @ref => @r, and @id => @i
SKIP_NULL_FIELDS // Do not write field values to output JSON when
// their value is null. If you have a
constructor that takes
// primitive wrapper arguments (ie., Integer),
json-io will
// supply their 'zero' value (0) when looking
for constructors
// to choose.
CLASSLOADER // ClassLoader instance to use when turning
String names of
// classes into JVM Class instances.
FORCE_MAP_FORMAT_ARRAY_KEYS_ITEMS // Force Map output to use
@keys/@Items even if
// the Map contains all Strings as keys.
…On Tue, May 12, 2020 at 5:22 AM goodandrewsoft ***@***.***> wrote:
public static class Foo {
private final int id;
private final String name;
public int getId() {
return id;
}
public String getName() {
return name;
}
public Foo() {
name = null;
id = 0;
}
public Foo(int id, String name) {
this.id = id;
this.name = name;
}
@OverRide
public String toString() {
return "Foo{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
@testpublic void whenSerializeAndDeserializeUsingJsonio_thenCorrect(){
Foo foo = new Foo(1,"first");
String jsonStr = JsonWriter.objectToJson(foo);
Foo result = (Foo) JsonReader.jsonToJava(jsonStr);
assertEquals(foo.getId(),result.getId());
}
String jsonStr = ***@***.***":"com.company.Main$Foo","id":1,"name":"first"}
How avoid print, the ***@***.*** <https://github.com/type>":"com.company.Main$Foo""
?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#148>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABI76TQK2F4AYPI2V46D4VTRREIOXANCNFSM4M6U3RKQ>
.