Revision 2979
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/json/JsonPathContextImpl.java | ||
---|---|---|
58 | 58 |
this.jsonObject = jsonObject; |
59 | 59 |
this.json = jsonObject.toString(); |
60 | 60 |
if( this.jsonObject!=null ) { |
61 |
this.context = JsonPath.parse(json); |
|
61 |
try { |
|
62 |
this.context = JsonPath.parse(json); |
|
63 |
} catch (com.jayway.jsonpath.PathNotFoundException ex) { |
|
64 |
throw new PathNotFoundException("Can't parse json path", ex); |
|
65 |
} |
|
62 | 66 |
} |
63 | 67 |
} |
64 | 68 |
|
... | ... | |
88 | 92 |
@Override |
89 | 93 |
public void setJsonObject(JsonStructure jsonObject) { |
90 | 94 |
this.jsonObject = jsonObject; |
91 |
if( this.jsonObject!=null ) { |
|
92 |
this.context = JsonPath.parse(jsonObject.toString()); |
|
95 |
if (this.jsonObject != null) { |
|
96 |
try { |
|
97 |
this.context = JsonPath.parse(jsonObject.toString()); |
|
98 |
} catch (com.jayway.jsonpath.PathNotFoundException ex) { |
|
99 |
throw new PathNotFoundException("Can't parse json path", ex); |
|
100 |
} |
|
93 | 101 |
} |
94 | 102 |
} |
95 | 103 |
|
96 | 104 |
@Override |
97 | 105 |
public Object get(String path) { |
98 |
Object r = this.context.read(path); |
|
99 |
return r; |
|
106 |
try { |
|
107 |
Object r = this.context.read(path); |
|
108 |
return r; |
|
109 |
} catch (com.jayway.jsonpath.PathNotFoundException ex) { |
|
110 |
throw new PathNotFoundException("Can't parse json path", ex); |
|
111 |
} |
|
100 | 112 |
} |
101 | 113 |
|
102 | 114 |
@Override |
103 | 115 |
public int getInt(String path, int defaultValue) { |
104 |
Object r = this.context.read(path);
|
|
116 |
Object r = this.get(path);
|
|
105 | 117 |
if( r == null ) { |
106 | 118 |
return defaultValue; |
107 | 119 |
} |
... | ... | |
113 | 125 |
|
114 | 126 |
@Override |
115 | 127 |
public long getLong(String path, long defaultValue) { |
116 |
Object r = this.context.read(path);
|
|
128 |
Object r = this.get(path);
|
|
117 | 129 |
if( r == null ) { |
118 | 130 |
return defaultValue; |
119 | 131 |
} |
... | ... | |
125 | 137 |
|
126 | 138 |
@Override |
127 | 139 |
public double getDouble(String path, double defaultValue) { |
128 |
Object r = this.context.read(path);
|
|
140 |
Object r = this.get(path);
|
|
129 | 141 |
if( r == null ) { |
130 | 142 |
return defaultValue; |
131 | 143 |
} |
... | ... | |
137 | 149 |
|
138 | 150 |
@Override |
139 | 151 |
public float getFloat(String path, float defaultValue) { |
140 |
Object r = this.context.read(path);
|
|
152 |
Object r = this.get(path);
|
|
141 | 153 |
if( r == null ) { |
142 | 154 |
return defaultValue; |
143 | 155 |
} |
... | ... | |
149 | 161 |
|
150 | 162 |
@Override |
151 | 163 |
public Date getDate(String path) { |
152 |
Object r = this.context.read(path);
|
|
164 |
Object r = this.get(path);
|
|
153 | 165 |
if( r == null ) { |
154 | 166 |
return null; |
155 | 167 |
} |
... | ... | |
161 | 173 |
|
162 | 174 |
@Override |
163 | 175 |
public Time getTime(String path) { |
164 |
Object r = this.context.read(path);
|
|
176 |
Object r = this.get(path);
|
|
165 | 177 |
if( r == null ) { |
166 | 178 |
return null; |
167 | 179 |
} |
... | ... | |
173 | 185 |
|
174 | 186 |
@Override |
175 | 187 |
public Timestamp getTimestamp(String path) { |
176 |
Object r = this.context.read(path);
|
|
188 |
Object r = this.get(path);
|
|
177 | 189 |
if( r == null ) { |
178 | 190 |
return null; |
179 | 191 |
} |
... | ... | |
185 | 197 |
|
186 | 198 |
@Override |
187 | 199 |
public JsonObject getJsonObject(String path) { |
188 |
Object r = this.context.read(path);
|
|
200 |
Object r = this.get(path);
|
|
189 | 201 |
if( r == null ) { |
190 | 202 |
return null; |
191 | 203 |
} |
... | ... | |
194 | 206 |
|
195 | 207 |
@Override |
196 | 208 |
public JsonArray getJsonArray(String path) { |
197 |
Object r = this.context.read(path);
|
|
209 |
Object r = this.get(path);
|
|
198 | 210 |
if( r == null ) { |
199 | 211 |
return null; |
200 | 212 |
} |
Also available in: Unified diff