Skip to content

Issue 36: Collection handling and deserializers for JSON-HAL #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
test-output/
.settings/
.project
.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.springframework.hateoas.hal;


import org.springframework.hateoas.Resource;

public class AnnotationBasedRelationResolver implements RelationResolver {

@SuppressWarnings("rawtypes")
@Override
public String getResourceRelation(Object resource) {

// check for hateoas wrapper type
if (Resource.class.isInstance(resource)) {
resource = ((Resource) resource).getContent();
}

HateoasRelation annotation = resource.getClass().getAnnotation(HateoasRelation.class);
if (annotation == null || HateoasRelation.NO_RELATION.equals(annotation.value())) {
return null;
}
return annotation.value();
}

}
16 changes: 16 additions & 0 deletions src/main/java/org/springframework/hateoas/hal/HateoasRelation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.springframework.hateoas.hal;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface HateoasRelation {

public static final String NO_RELATION = "";

String value() default NO_RELATION;

}
Loading