use of com.helger.json.IJson in project phoss-smp by phax.
the class SMPBusinessCardManagerJDBC method getJsonAsString.
@Nonnull
public static ICommonsList<String> getJsonAsString(@Nullable final String sJson) {
final ICommonsList<String> ret = new CommonsArrayList<>();
final IJson aJson = sJson == null ? null : JsonReader.readFromString(sJson);
if (aJson != null && aJson.isArray())
for (final IJson aItem : aJson.getAsArray()) {
final String sValue = aItem.getAsValue().getAsString();
ret.add(sValue);
}
return ret;
}
use of com.helger.json.IJson in project ph-web by phax.
the class ResponseHandlerJson method handleResponse.
@Nullable
public IJson handleResponse(@Nonnull final HttpResponse aHttpResponse) throws IOException {
final HttpEntity aEntity = ResponseHandlerHttpEntity.INSTANCE.handleResponse(aHttpResponse);
if (aEntity == null)
throw new ClientProtocolException("Response contains no content");
final ContentType aContentType = ContentType.getOrDefault(aEntity);
final Charset aCharset = HttpClientHelper.getCharset(aContentType, m_aFallbackCharset);
if (m_bDebugMode) {
// Read all in String
final String sJson = StringHelper.trim(EntityUtils.toString(aEntity, aCharset));
if (LOGGER.isInfoEnabled())
LOGGER.info("Got JSON: <" + sJson + ">");
final IJson ret = JsonReader.readFromString(sJson);
if (ret == null)
throw new IllegalArgumentException("Failed to parse as JSON: " + sJson);
return ret;
}
// Read via reader to avoid duplication in memory
return JsonReader.builder().source(aEntity.getContent(), aCharset).read();
}
Aggregations