@@ -110,29 +110,6 @@ public static <T> T createEntity(String jsonText, Type type) {
110110 }
111111
112112 public static <T > String toJsonString (T obj ) {
113- if (obj .getClass ().equals (BaseDocument .class )) {
114- String tmp = toJsonString (obj , true );
115- JsonParser jsonParser = new JsonParser ();
116- JsonElement jsonElement = jsonParser .parse (tmp );
117- JsonObject jsonObject = jsonElement .getAsJsonObject ();
118- JsonObject result = jsonObject .getAsJsonObject ("properties" );
119- JsonElement keyObject = jsonObject .get ("_key" );
120- if (keyObject != null && keyObject .getClass () != JsonNull .class ) {
121- result .add ("_key" , jsonObject .get ("_key" ));
122- }
123- JsonElement handleObject = jsonObject .get ("_id" );
124- if (handleObject != null && handleObject .getClass () != JsonNull .class ) {
125- result .add ("_id" , jsonObject .get ("_id" ));
126- }
127- // JsonElement revisionValue = jsonObject.get("documentRevision");
128- // result.add("_rev", revisionValue);
129- System .out .println ("************" );
130- System .out .println (result .toString ());
131- System .out .println (jsonObject .toString ());
132- System .out .println (toJsonString (obj , false ));
133- System .out .println ("************" );
134- return result .toString ();
135- }
136113 return toJsonString (obj , false );
137114 }
138115
@@ -151,6 +128,24 @@ public static <T> String toImportHeaderValues(Collection<? extends Collection<?>
151128 }
152129
153130 public static <T > String toJsonString (T obj , boolean includeNullValue ) {
131+ if (obj .getClass ().equals (BaseDocument .class )) {
132+ String tmp = includeNullValue ? gsonNull .toJson (obj ) : gson .toJson (obj );
133+ JsonParser jsonParser = new JsonParser ();
134+ JsonElement jsonElement = jsonParser .parse (tmp );
135+ JsonObject jsonObject = jsonElement .getAsJsonObject ();
136+ JsonObject result = jsonObject .getAsJsonObject ("properties" );
137+ JsonElement keyObject = jsonObject .get ("_key" );
138+ if (keyObject != null && keyObject .getClass () != JsonNull .class ) {
139+ result .add ("_key" , jsonObject .get ("_key" ));
140+ }
141+ JsonElement handleObject = jsonObject .get ("_id" );
142+ if (handleObject != null && handleObject .getClass () != JsonNull .class ) {
143+ result .add ("_id" , jsonObject .get ("_id" ));
144+ }
145+ // JsonElement revisionValue = jsonObject.get("documentRevision");
146+ // result.add("_rev", revisionValue);
147+ return result .toString ();
148+ }
154149 return includeNullValue ? gsonNull .toJson (obj ) : gson .toJson (obj );
155150 }
156151
0 commit comments