private JsonResponse(int statusCode, String statusMessage, Headers headers, String responseBody, JsonCodec<T> jsonCodec) { this.statusCode = statusCode; this.statusMessage = statusMessage; this.headers = requireNonNull(headers, "headers is null"); this.responseBody = requireNonNull(responseBody, "responseBody is null"); T value = null; IllegalArgumentException exception = null; try { value = jsonCodec.fromJson(responseBody); } catch (IllegalArgumentException e) { exception = new IllegalArgumentException(format("Unable to create %s from JSON response:\n[%s]", jsonCodec.getType(), responseBody), e); } this.hasValue = (exception == null); this.value = value; this.exception = exception; }
private JsonResponse(int statusCode, String statusMessage, Headers headers, String responseBody, JsonCodec<T> jsonCodec) { this.statusCode = statusCode; this.statusMessage = statusMessage; this.headers = requireNonNull(headers, "headers is null"); this.responseBody = requireNonNull(responseBody, "responseBody is null"); T value = null; IllegalArgumentException exception = null; try { value = jsonCodec.fromJson(responseBody); } catch (IllegalArgumentException e) { exception = new IllegalArgumentException(format("Unable to create %s from JSON response:\n[%s]", jsonCodec.getType(), responseBody), e); } this.hasValue = (exception == null); this.value = value; this.exception = exception; }
public void bindMapJsonCodec(Class<?> keyType, JsonCodec<?> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); ParameterizedTypeImpl mapType = new ParameterizedTypeImpl(null, Map.class, keyType, valueType.getType()); binder.bind(getJsonCodecKey(mapType)).toProvider(new JsonCodecProvider(mapType)).in(Scopes.SINGLETON); }
public void bindListJsonCodec(JsonCodec<?> type) { Preconditions.checkNotNull(type, "type is null"); ParameterizedTypeImpl listType = new ParameterizedTypeImpl(null, List.class, type.getType()); binder.bind(getJsonCodecKey(listType)).toProvider(new JsonCodecProvider(listType)).in(Scopes.SINGLETON); }
public void bindMapJsonCodec(Class<?> keyType, JsonCodec<?> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); ParameterizedTypeImpl mapType = new ParameterizedTypeImpl(null, Map.class, keyType, valueType.getType()); binder.bind(getJsonCodecKey(mapType)).toProvider(new JsonCodecProvider(mapType)).in(Scopes.SINGLETON); }
public void bindMapJsonCodec(Class<?> keyType, JsonCodec<?> valueType) { Preconditions.checkNotNull(keyType, "keyType is null"); Preconditions.checkNotNull(valueType, "valueType is null"); ParameterizedTypeImpl mapType = new ParameterizedTypeImpl(null, Map.class, keyType, valueType.getType()); binder.bind(getJsonCodecKey(mapType)).toProvider(new JsonCodecProvider(mapType)).in(Scopes.SINGLETON); }
public void bindListJsonCodec(JsonCodec<?> type) { requireNonNull(type, "type is null"); ParameterizedTypeImpl listType = new ParameterizedTypeImpl(null, List.class, type.getType()); binder.bind(getJsonCodecKey(listType)).toProvider(new JsonCodecProvider(listType)).in(Scopes.SINGLETON); }
public void bindListJsonCodec(JsonCodec<?> type) { requireNonNull(type, "type is null"); ParameterizedTypeImpl listType = new ParameterizedTypeImpl(null, List.class, type.getType()); binder.bind(getJsonCodecKey(listType)).toProvider(new JsonCodecProvider(listType)).in(Scopes.SINGLETON); }
@SuppressWarnings("ThrowableInstanceNeverThrown") public JsonResponse(int statusCode, String statusMessage, ListMultimap<HeaderName, String> headers, JsonCodec<T> jsonCodec, byte[] jsonBytes) { this.statusCode = statusCode; this.statusMessage = statusMessage; this.headers = ImmutableListMultimap.copyOf(headers); this.jsonBytes = requireNonNull(jsonBytes, "jsonBytes is null"); this.responseBytes = requireNonNull(jsonBytes, "responseBytes is null"); T value = null; IllegalArgumentException exception = null; try { value = jsonCodec.fromJson(jsonBytes); } catch (IllegalArgumentException e) { exception = new IllegalArgumentException(format("Unable to create %s from JSON response:\n[%s]", jsonCodec.getType(), getJson()), e); } this.hasValue = (exception == null); this.value = value; this.exception = exception; }
throw new IllegalArgumentException(String.format("Unable to create %s from JSON response:\n[%s]", jsonCodec.getType(), json), e);