Revision 2401 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/json/JsonManagerImpl.java

View differences:

JsonManagerImpl.java
9 9
import java.util.HashMap;
10 10
import java.util.Iterator;
11 11
import java.util.Map;
12
import java.util.Objects;
12 13
import javax.json.JsonArray;
13 14
import javax.json.JsonNumber;
14 15
import javax.json.JsonObject;
......
149 150
        }
150 151
    }
151 152

  
152
    @Override
153
    public String toString(JsonObject obj) {
154
        return this.toString((JsonStructure) obj);
155
    }
156

  
157
    @Override
158
    public String toString(JsonArray array) {
159
        return this.toString((JsonStructure) array);
160
    }
161

  
162
    @Override
163
    public String toString(JsonStructure obj) {
153
    private String toString(JsonStructure obj) {
164 154
        StringWriter sw = new StringWriter();
165 155
        JsonWriterFactory writerFactory = javax.json.Json.createWriterFactory(
166 156
                Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)
......
171 161
        String s = sw.toString();
172 162
        return s;
173 163
    }
164
    
165
    @Override
166
    public String toString(JsonValue value) {
167
        if( value == null ) {
168
            return Objects.toString(null);
169
        }
170
        switch (value.getValueType()) {
171
            case ARRAY:
172
            case OBJECT:
173
                return this.toString((JsonStructure)value);
174
            case FALSE:
175
            case NUMBER:
176
            case STRING:
177
            case TRUE:
178
            case NULL:
179
            default:
180
                return value.toString();
181
        }
182
    }
174 183

  
184

  
175 185
    @Override
176
    public Object toObject(String name, JsonObject json) {
186
    public Object toObject(JsonObject json, String name) {
177 187
        JsonValue value = json.get(name);
178 188
        return toObject(value);
179 189
    }
180 190

  
181 191
    @Override
182
    public Object toObject(int index, JsonArray json) {
192
    public Object toObject(JsonArray json, int index) {
183 193
        JsonValue value = json.get(index);
184 194
        return toObject(value);
185 195
    }
186 196

  
187
    @Override
188
    public Object toObject(JsonObject json) {
189
        return this.toObject(json, null);
190
    }
191

  
192
    @Override
193
    public Object toObject(JsonObject json, Object defaultValue) {
197
    private Object createObject(JsonObject json, Object defaultValue) {
194 198
        if (json == null) {
195 199
            return defaultValue;
196 200
        }
......
283 287

  
284 288
    @Override
285 289
    public Object toObject(JsonValue value) {
290
        return this.toObjectOrDefault(value, null);
291
    }
292

  
293
    @Override
294
    public Object toObjectOrDefault(JsonValue value, Object defaultValue) {
286 295
        if( value == null ) {
287
            return null;
296
            return defaultValue;
288 297
        }
289 298
        switch (value.getValueType()) {
290 299
            case ARRAY:
......
312 321
                }
313 322

  
314 323
            case OBJECT:
315
                return this.toObject((JsonObject) value, value);
324
                return this.createObject((JsonObject) value, defaultValue);
316 325

  
317 326
            case STRING:
318 327
                return ((JsonString) value).getString();
319 328
            case TRUE:
320
                return false;
329
                return true;
321 330
            case NULL:
331
                return null;
322 332
            default:
323
                return null;
333
                return defaultValue;
324 334
        }
325 335
    }
326 336

  
......
345 355
    }
346 356

  
347 357
    @Override
348
    public Map toHashMap(JsonObject json) {
358
    public Map toMap(JsonObject json) {
349 359
        if( json == null ) {
350 360
            return null;
351 361
        }

Also available in: Unified diff