Skip to content

Instantly share code, notes, and snippets.

@ariens
Created July 29, 2015 13:21
Show Gist options
  • Save ariens/55f8830ec8144f6c6b25 to your computer and use it in GitHub Desktop.
Save ariens/55f8830ec8144f6c6b25 to your computer and use it in GitHub Desktop.
An extension of com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector
/*
* Copyright 2015 dariens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.blackberry.bdp.common.versioned;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class was an attempt at limiting attributes for serialization
* and de-serialization based on the VersionedAttribute annotation
* however when applied to an mapper the resulting serialized string
* is empty.
*/
public class VersionedAnnotationIntrospector extends NopAnnotationIntrospector {
private static final Logger LOG = LoggerFactory.getLogger(VersionedAnnotationIntrospector.class);
@Override
public boolean hasIgnoreMarker(final AnnotatedMember m) {
if (m.hasAnnotation(VersionedAttribute.class)) {
LOG.info("member {} has anno", m);
return false;
} else {
LOG.info("member {} DOES NOT have anno", m);
return true;
}
}
/*
@Override
public Boolean hasRequiredMarker(AnnotatedMember m) {
if (m.hasAnnotation(VersionedAttribute.class)) {
LOG.info("member {} has anno", m);
return true;
}
return null;
}
*/
}
@ariens
Copy link
Author

ariens commented Oct 8, 2015

Legacy/Deprecated--concept was cool but I opted for mixin's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment