Skip to content

Commit

Permalink
Capitalize JSON in JsonCodec error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Sep 27, 2016
1 parent 56b7973 commit 98e1be7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Expand Up @@ -60,7 +60,7 @@ public void testInvalidJson()
assertFalse(response.hasValue());
assertEquals(response.getException().getMessage(), format("Unable to create %s from JSON response:\n[%s]", User.class, json));
assertTrue(response.getException().getCause() instanceof IllegalArgumentException);
assertEquals(response.getException().getCause().getMessage(), "Invalid json bytes for [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User]");
assertEquals(response.getException().getCause().getMessage(), "Invalid JSON bytes for [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User]");

assertEquals(response.getJsonBytes(), json.getBytes(UTF_8));
assertEquals(response.getJson(), json);
Expand Down
Expand Up @@ -42,7 +42,7 @@ public void testInvalidJson()
catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), format("Unable to create %s from JSON response:\n[%s]", User.class, json));
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertEquals(e.getCause().getMessage(), "Invalid json bytes for [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User]");
assertEquals(e.getCause().getMessage(), "Invalid JSON bytes for [simple type, class io.airlift.http.client.TestFullJsonResponseHandler$User]");
}
}

Expand Down
11 changes: 6 additions & 5 deletions json/src/main/java/io/airlift/json/JsonCodec.java
Expand Up @@ -32,6 +32,7 @@

import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;

public class JsonCodec<T>
{
Expand Down Expand Up @@ -138,7 +139,7 @@ public T fromJson(String json)
return mapper.readValue(json, javaType);
}
catch (IOException e) {
throw new IllegalArgumentException(String.format("Invalid json string for %s", javaType), e);
throw new IllegalArgumentException(format("Invalid JSON string for %s", javaType), e);
}
}

Expand All @@ -156,7 +157,7 @@ public String toJson(T instance)
return mapper.writeValueAsString(instance);
}
catch (IOException e) {
throw new IllegalArgumentException(String.format("%s could not be converted to json", instance.getClass().getName()), e);
throw new IllegalArgumentException(format("%s could not be converted to JSON", instance.getClass().getName()), e);
}
}

Expand All @@ -179,7 +180,7 @@ public Optional<String> toJsonWithLengthLimit(T instance, int lengthLimit)
return Optional.empty();
}
catch (IOException e) {
throw new IllegalArgumentException(String.format("%s could not be converted to json", instance.getClass().getName()), e);
throw new IllegalArgumentException(format("%s could not be converted to JSON", instance.getClass().getName()), e);
}
}

Expand All @@ -197,7 +198,7 @@ public T fromJson(byte[] json)
return mapper.readValue(json, javaType);
}
catch (IOException e) {
throw new IllegalArgumentException(String.format("Invalid json bytes for %s", javaType), e);
throw new IllegalArgumentException(format("Invalid JSON bytes for %s", javaType), e);
}
}

Expand All @@ -215,7 +216,7 @@ public byte[] toJsonBytes(T instance)
return mapper.writeValueAsBytes(instance);
}
catch (IOException e) {
throw new IllegalArgumentException(String.format("%s could not be converted to json", instance.getClass().getName()), e);
throw new IllegalArgumentException(format("%s could not be converted to JSON", instance.getClass().getName()), e);
}
}

Expand Down

0 comments on commit 98e1be7

Please sign in to comment.