Skip to content

Commit

Permalink
#218 do not introduce dependency on jackson-databind if not used
Browse files Browse the repository at this point in the history
  • Loading branch information
elucash committed Dec 11, 2015
1 parent 5c5fc72 commit 5e697de
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Expand Up @@ -3,7 +3,7 @@
import org.immutables.value.Value;

@Value.Immutable
@Value.Style
@MetaJacksonAnnotation
public interface JacksonMappedWithNoAnnotations {
String getSomeString();
}
Expand Up @@ -1542,7 +1542,7 @@ private [v.type] [invokeSuperGet]() {
[/output.trim][/template]

[template generateJacksonMapped Type type]
[if type.generateJacksonMapped or classpath.available 'com.fasterxml.jackson.annotation.JsonCreator']
[if type.generateJacksonMapped and (classpath.available 'com.fasterxml.jackson.annotation.JsonCreator')]
[if type.implementedAttributes]

/**
Expand Down
Expand Up @@ -310,7 +310,7 @@ public boolean isJacksonSerialized() {

@Value.Lazy
public boolean isJacksonDeserialized() {
if (isJacksonDeserializedAnnotated(element())) {
if (isJacksonDeserializedAnnotated()) {
// while DeclaringPackage cannot have those annotations
// directly, just checking them as a general computation path
// will not hurt much.
Expand All @@ -325,6 +325,11 @@ public boolean isJacksonDeserialized() {
return false;
}

@Value.Lazy
public boolean isJacksonDeserializedAnnotated() {
return Proto.isJacksonDeserializedAnnotated(element());
}

@Value.Lazy
public boolean isJacksonJsonTypeInfo() {
if (isJacksonJsonTypeInfoAnnotated(element())) {
Expand Down Expand Up @@ -1198,7 +1203,7 @@ public StyleInfo apply(StyleMirror input) {
"com.fasterxml.jackson.databind.annotation.JsonSerialize",
"com.fasterxml.jackson.databind.annotation.JsonDeserialize");

private static boolean isJacksonSerializedAnnotated(Element element) {
static boolean isJacksonSerializedAnnotated(Element element) {
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror annotation : annotationMirrors) {
TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
Expand All @@ -1209,7 +1214,7 @@ private static boolean isJacksonSerializedAnnotated(Element element) {
return false;
}

private static boolean isJacksonDeserializedAnnotated(Element element) {
static boolean isJacksonDeserializedAnnotated(Element element) {
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror annotation : annotationMirrors) {
TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
Expand All @@ -1221,7 +1226,7 @@ private static boolean isJacksonDeserializedAnnotated(Element element) {
return false;
}

protected static boolean isJacksonJsonTypeInfoAnnotated(Element element) {
static boolean isJacksonJsonTypeInfoAnnotated(Element element) {
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror annotation : annotationMirrors) {
TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
Expand Down
Expand Up @@ -242,7 +242,9 @@ public boolean isGenerateJacksonMapped() {
}

public boolean isJacksonDeserialized() {
return constitution.protoclass().isJacksonDeserialized();
Optional<DeclaringType> declaringType = constitution.protoclass().declaringType();
return declaringType.isPresent()
&& declaringType.get().isJacksonDeserializedAnnotated();
}

public boolean isJacksonJsonTypeInfo() {
Expand Down

1 comment on commit 5e697de

@ldriscoll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a good fix, thanks

Please sign in to comment.