Permalink
Browse files

Add Spring support for legacy application/x-jsimpledb-transaction MIM…

…E type.
  • Loading branch information...
archiecobbs committed Oct 28, 2017
1 parent 3f31a25 commit e6f708a7d4977b3e8b76ca03c6f8faf0946cc23d
View
@@ -1,3 +1,7 @@
Version Next
- Added Spring support for legacy application/x-jsimpledb-transaction MIME type
Version 4.0.1 Released October 23, 2017
- Added support for import/export of POJO's (issue #24)
@@ -55,7 +55,18 @@
* @throws IllegalArgumentException if {@code jdb} is null
*/
public JObjectHttpMessageConverter(Permazen jdb) {
super(SnapshotJTransactionHttpMessageConverter.MIME_TYPE);
this(jdb, SnapshotJTransactionHttpMessageConverter.MIME_TYPE, SnapshotJTransactionHttpMessageConverter.LEGACY_MIME_TYPE);
}
/**
* Constructor.
*
* @param jdb {@link Permazen} instance
* @param supportedMediaTypes supported media types
* @throws IllegalArgumentException if {@code jdb} is null
*/
public JObjectHttpMessageConverter(Permazen jdb, MediaType... supportedMediaTypes) {
super(supportedMediaTypes);
Preconditions.checkArgument(jdb != null, "null jdb");
this.jdb = jdb;
}
@@ -98,7 +109,7 @@ protected boolean supports(Class<?> target) {
@Override
protected MediaType getDefaultContentType(JObject jobj) {
Preconditions.checkArgument(jobj != null, "null jobj");
return new MediaType(SnapshotJTransactionHttpMessageConverter.MIME_TYPE,
return new MediaType(this.getSupportedMediaTypes().get(0),
Collections.<String, String>singletonMap(ROOT_OBJECT_ID_PARAMETER_NAME, jobj.getObjId().toString()));
}
@@ -111,8 +122,6 @@ protected JObject readInternal(Class<? extends JObject> type, HttpInputMessage i
// Get the root object's ID
final MediaType mediaType = input.getHeaders().getContentType();
if (!SnapshotJTransactionHttpMessageConverter.MIME_TYPE.includes(mediaType))
throw new HttpMessageNotReadableException("invalid Content-Type `" + mediaType + "'");
final String objId = mediaType.getParameter(ROOT_OBJECT_ID_PARAMETER_NAME);
if (objId == null) {
throw new HttpMessageNotReadableException("required parameter `" + ROOT_OBJECT_ID_PARAMETER_NAME
@@ -47,6 +47,8 @@
*/
public static final MediaType MIME_TYPE = new MediaType("application", "x-permazen-transaction");
static final MediaType LEGACY_MIME_TYPE = new MediaType("application", "x-jsimpledb-transaction");
private final Permazen jdb;
private Class<?>[] validationGroups;
@@ -57,7 +59,17 @@
* @param jdb {@link Permazen} instance defining the convertible types
*/
public SnapshotJTransactionHttpMessageConverter(Permazen jdb) {
super(MIME_TYPE);
this(jdb, MIME_TYPE, LEGACY_MIME_TYPE);
}
/**
* Constructor.
*
* @param jdb {@link Permazen} instance defining the convertible types
* @param supportedMediaTypes supported media types
*/
public SnapshotJTransactionHttpMessageConverter(Permazen jdb, MediaType... supportedMediaTypes) {
super(supportedMediaTypes);
Preconditions.checkArgument(jdb != null, "null jdb");
this.jdb = jdb;
}

0 comments on commit e6f708a

Please sign in to comment.