com.fasterxml.jackson.annotation.JsonIgnoreProperties Java Examples

The following examples show how to use com.fasterxml.jackson.annotation.JsonIgnoreProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanSerializerFactory.java    From bistoury with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Overridable method that can filter out properties. Default implementation
 * checks annotations class may have.
 */
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config,
                                                        BeanDescription beanDesc, List<BeanPropertyWriter> props)
{
    // 01-May-2016, tatu: Which base type to use here gets tricky, since
    //   it may often make most sense to use general type for overrides,
    //   but what we have here may be more specific impl type. But for now
    //   just use it as is.
    JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(beanDesc.getBeanClass(),
            beanDesc.getClassInfo());
    if (ignorals != null) {
        Set<String> ignored = ignorals.findIgnoredForSerialization();
        if (!ignored.isEmpty()) {
            Iterator<BeanPropertyWriter> it = props.iterator();
            while (it.hasNext()) {
                if (ignored.contains(it.next().getName())) {
                    it.remove();
                }
            }
        }
    }
    return props;
}
 
Example #2
Source File: StageScalingPolicy.java    From mantis with Apache License 2.0 6 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public StageScalingPolicy(@JsonProperty("stage") int stage,
                          @JsonProperty("min") int min, @JsonProperty("max") int max,
                          @JsonProperty("increment") int increment, @JsonProperty("decrement") int decrement,
                          @JsonProperty("coolDownSecs") long coolDownSecs,
                          @JsonProperty("strategies") Map<ScalingReason, Strategy> strategies) {
    this.stage = stage;
    this.min = min;
    this.max = Math.max(max, min);
    enabled = min != max && strategies != null && !strategies.isEmpty();
    this.increment = Math.max(increment, 1);
    this.decrement = Math.max(decrement, 1);
    this.coolDownSecs = coolDownSecs;
    this.strategies = strategies == null ? new HashMap<ScalingReason, Strategy>() : new HashMap<>(strategies);
}
 
Example #3
Source File: Library.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * Loops over all constructs in order to find the distinct set of {@link ProgrammingLanguage}s used to develop the library.
 * Note: If slow, it can maybe improved by using a JPQL query.
 *
 * @return a {@link java.util.Set} object.
 */
@JsonProperty(value = "developedIn")
@JsonView(Views.CountDetails.class)
@JsonIgnoreProperties(value = { "developedIn" }, allowGetters=true)
public Set<ProgrammingLanguage> getDevelopedIn() {
	if(this.developedIn==null) {
		this.developedIn = new HashSet<ProgrammingLanguage>();
		if(this.getConstructs()!=null) {
			for(ConstructId cid: this.getConstructs()) {
				if(!this.developedIn.contains(cid.getLang())) {
					this.developedIn.add(cid.getLang());
				}
			}
		}
	}
	return this.developedIn;
}
 
Example #4
Source File: MySlice.java    From biliob_backend with MIT License 6 votes vote down vote up
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
@JsonIgnoreProperties({"sort", "pageable"})
public MySlice(
        @JsonProperty("content") List<T> content,
        @JsonProperty("number") Integer number,
        @JsonProperty("size") Integer size,
        @JsonProperty("first") Boolean first,
        @JsonProperty("numberOfElements") Integer numberOfElements,
        @JsonProperty("last") Boolean last) {
    this.content = content;
    this.number = number;
    this.size = size;
    this.last = last;
    this.first = first;
    this.numberOfElements = numberOfElements;
}
 
Example #5
Source File: BeanSerializerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Overridable method that can filter out properties. Default implementation
 * checks annotations class may have.
 */
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config,
        BeanDescription beanDesc, List<BeanPropertyWriter> props)
{
    // 01-May-2016, tatu: Which base type to use here gets tricky, since
    //   it may often make most sense to use general type for overrides,
    //   but what we have here may be more specific impl type. But for now
    //   just use it as is.
    JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(beanDesc.getBeanClass(),
            beanDesc.getClassInfo());
    if (ignorals != null) {
        Set<String> ignored = ignorals.findIgnoredForSerialization();
        if (!ignored.isEmpty()) {
            Iterator<BeanPropertyWriter> it = props.iterator();
            while (it.hasNext()) {
                if (ignored.contains(it.next().getName())) {
                    it.remove();
                }
            }
        }
    }
    return props;
}
 
Example #6
Source File: JsonIgnorePropertiesAnnotationTest.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Description(
        "This test verifies that all model classes within the 'org.eclipse.hawkbit.ddi.json.model' package are annotated with '@JsonIgnoreProperties(ignoreUnknown = true)'")
public void shouldCheckAnnotationsForAllModelClasses() throws IOException {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    String packageName = this.getClass().getPackage().getName();

    ImmutableSet<ClassPath.ClassInfo> topLevelClasses = ClassPath.from(loader).getTopLevelClasses(packageName);
    for (ClassPath.ClassInfo classInfo : topLevelClasses) {
        Class<?> modelClass = classInfo.load();
        if (modelClass.getSimpleName().contains("Test") || modelClass.isEnum()) {
            continue;
        }
        JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class);
        assertThat(annotation).isNotNull();
        assertThat(annotation.ignoreUnknown()).isTrue();
    }
}
 
Example #7
Source File: JobInfo.java    From mantis with Apache License 2.0 6 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public JobInfo(
        @JsonProperty("name") final String name,
        @JsonProperty("description") final String description,
        @JsonProperty("numberOfStages") final int numberOfStages,
        @JsonProperty("parameterInfo") final Map<String, ParameterInfo> parameterInfo,
        @JsonProperty("sourceInfo") final MetadataInfo sourceInfo,
        @JsonProperty("sinkInfo") final MetadataInfo sinkInfo,
        @JsonProperty("stages") final Map<Integer, StageInfo> stages) {
    super(name, description);
    this.numberOfStages = numberOfStages;
    this.parameterInfo = parameterInfo;
    this.sourceInfo = sourceInfo;
    this.sinkInfo = sinkInfo;
    this.stages = stages;
}
 
Example #8
Source File: AppJobClustersMap.java    From mantis with Apache License 2.0 6 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public AppJobClustersMap(@JsonProperty("version") String version,
                         @JsonProperty("timestamp") long ts,
                         @JsonProperty("mappings") Map<String, Object> mappings) {
    checkNotNull(mappings, "mappings");
    checkNotNull(version, "version");
    this.timestamp = ts;
    if (!version.equals(VERSION_1)) {
        throw new IllegalArgumentException("version " + version + " is not supported");
    }
    this.version = version;

    mappings.entrySet()
            .stream()
            .forEach(e -> this.mappings.put(e.getKey(), (Map<String, String>) e.getValue()));
}
 
Example #9
Source File: GuavaSerializers.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config,
        MapLikeType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides,
        JsonSerializer<Object> keySerializer,
        TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
{
    if (Multimap.class.isAssignableFrom(type.getRawClass())) {
        final AnnotationIntrospector intr = config.getAnnotationIntrospector();
        Object filterId = intr.findFilterId(config, (Annotated)beanDesc.getClassInfo());
        JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(Multimap.class,
                beanDesc.getClassInfo());
        Set<String> ignored = (ignorals == null) ? null : ignorals.getIgnored();
        return new MultimapSerializer(type, beanDesc,
                keySerializer, elementTypeSerializer, elementValueSerializer, ignored, filterId);
    }
    return null;
}
 
Example #10
Source File: Measurements.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public Measurements(
        @JsonProperty("name") String name,
        @JsonProperty("timestamp") long timestamp,
        @JsonProperty("counters") Collection<CounterMeasurement> counters,
        @JsonProperty("gauges") Collection<GaugeMeasurement> gauges,
        @JsonProperty("tags") Map<String, String> tags) {
    this.name = name;
    this.timestamp = timestamp;
    this.counters = counters;
    this.gauges = gauges;
    this.tags = tags;
}
 
Example #11
Source File: JobDiscoveryInfo.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public JobDiscoveryInfo(@JsonProperty("jobCluster") final String jobCluster,
                        @JsonProperty("jobId") final String jobId,
                        @JsonProperty("stageWorkersMap") final Map<Integer, StageWorkers> stageWorkersMap) {
    this.jobCluster = jobCluster;
    this.jobId = jobId;
    this.stageWorkersMap = stageWorkersMap;
}
 
Example #12
Source File: JobDescriptor.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public JobDescriptor(
        @JsonProperty("jobInfo") JobInfo jobInfo,
        @JsonProperty("project") String project,
        @JsonProperty("version") String version,
        @JsonProperty("timestamp") long timestamp,
        @JsonProperty("readyForJobMaster") boolean readyForJobMaster) {
    this.jobInfo = jobInfo;
    this.version = version;
    this.timestamp = timestamp;
    this.project = project;
    this.readyForJobMaster = readyForJobMaster;
}
 
Example #13
Source File: MetadataInfo.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public MetadataInfo(@JsonProperty("name") String name,
                    @JsonProperty("description") String description) {
    this.name = name;
    this.description = description;
}
 
Example #14
Source File: StageInfo.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public StageInfo(@JsonProperty("stageNumber") int stageNumber,
                 @JsonProperty("description") String description) {
    this.stageNumber = stageNumber;
    this.description = description;
}
 
Example #15
Source File: ParameterInfo.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public ParameterInfo(@JsonProperty("name") String name,
                     @JsonProperty("description") String description,
                     @JsonProperty("defaultValue") String defaultValue,
                     @JsonProperty("parmaterType") String parameterType,
                     @JsonProperty("validatorDescription") String validatorDescription,
                     @JsonProperty("required") boolean required) {
    this.name = name;
    this.description = description;
    this.defaultValue = defaultValue;
    this.parameterType = parameterType;
    this.validatorDescription = validatorDescription;
    this.required = required;
}
 
Example #16
Source File: StreamJobClusterMap.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public StreamJobClusterMap(final String appName,
                           final Map<String, String> mappings) {
    this.appName = appName;
    this.mappings = mappings;
}
 
Example #17
Source File: MachineDefinition.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public MachineDefinition(@JsonProperty("cpuCores") double cpuCores,
                         @JsonProperty("memoryMB") double memoryMB,
                         @JsonProperty("networkMbps") double networkMbps,
                         @JsonProperty("diskMB") double diskMB,
                         @JsonProperty("numPorts") int numPorts) {
    this.cpuCores = cpuCores;
    this.memoryMB = memoryMB;
    this.networkMbps = networkMbps == 0 ? defaultMbps : networkMbps;
    this.diskMB = diskMB;
    this.numPorts = Math.max(minPorts, numPorts);
}
 
Example #18
Source File: StageSchedulingInfo.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public StageSchedulingInfo(@JsonProperty("numberOfInstances") int numberOfInstances,
                           @JsonProperty("machineDefinition") MachineDefinition machineDefinition,
                           @JsonProperty("hardConstraints") List<JobConstraints> hardConstraints,
                           @JsonProperty("softConstraints") List<JobConstraints> softConstraints,
                           @JsonProperty("scalingPolicy") StageScalingPolicy scalingPolicy,
                           @JsonProperty("scalable") boolean scalable) {
    this.numberOfInstances = numberOfInstances;
    this.machineDefinition = machineDefinition;
    this.hardConstraints = hardConstraints;
    this.softConstraints = softConstraints;
    this.scalingPolicy = scalingPolicy;
    this.scalable = scalable;
}
 
Example #19
Source File: WorkerPorts.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public WorkerPorts(@JsonProperty("metricsPort") int metricsPort,
                   @JsonProperty("debugPort") int debugPort,
                   @JsonProperty("consolePort") int consolePort,
                   @JsonProperty("customPort") int customPort,
                   @JsonProperty("ports") List<Integer> ports) {
    this.metricsPort = metricsPort;
    this.debugPort = debugPort;
    this.consolePort = consolePort;
    this.customPort = customPort;
    this.ports = ports;
}
 
Example #20
Source File: GaugeMeasurement.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public GaugeMeasurement(@JsonProperty("event") String event,
                        @JsonProperty("value") double value) {
    this.event = event;
    this.value = value;
}
 
Example #21
Source File: CounterMeasurement.java    From mantis with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public CounterMeasurement(@JsonProperty("event") String event,
                          @JsonProperty("count") long count) {
    this.event = event;
    this.count = count;
}
 
Example #22
Source File: DefaultEndPoint.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@Override
@JsonIgnoreProperties(ignoreUnknown = true)
public String getPassword() {
	
	String []userInfo = getUserInfo();
	if(userInfo == null || userInfo.length != 2){
		return null;
	}
	return userInfo[1];
}
 
Example #23
Source File: Library.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Note: Aggregates ignoring the programming language.
 *
 * @return a {@link com.sap.psr.vulas.backend.model.ConstructIdFilter} object.
 */
@JsonProperty(value = "constructTypeCounters")
@JsonView(Views.CountDetails.class)
@JsonIgnoreProperties(value = { "constructTypeCounters" }, allowGetters=true)
public ConstructIdFilter countConstructTypes() {
	if(this.filter==null)
		this.filter = new ConstructIdFilter(this.getConstructs());
	return this.filter;
}
 
Example #24
Source File: DefaultEndPoint.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@Override
@JsonIgnoreProperties(ignoreUnknown = true)
public String getUser() {

	String []userInfo = getUserInfo();
	if(userInfo == null || userInfo.length != 2){
		return null;
	}
	return userInfo[0];
}
 
Example #25
Source File: AptDeserializerBuilder.java    From domino-jackson with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Set<MethodSpec> moreMethods() {
    Set<MethodSpec> methods = new HashSet<>();
    // Object instance can be created by InstanceBuilder
    // only for non-abstract classes
    if (beanType.getKind() == TypeKind.DECLARED
            && ((DeclaredType) beanType).asElement().getKind() == ElementKind.CLASS
            && !((DeclaredType) beanType).asElement().getModifiers().contains(Modifier.ABSTRACT)) {
        methods.add(buildInitInstanceBuilderMethod());
    }

    MethodSpec initIgnoreFieldsMethod = buildInitIgnoreFields(beanType);
    if (nonNull(initIgnoreFieldsMethod)) {
        methods.add(initIgnoreFieldsMethod);
    }

    JsonIgnoreProperties ignorePropertiesAnnotation = typeUtils.asElement(beanType).getAnnotation(JsonIgnoreProperties.class);

    if (nonNull(ignorePropertiesAnnotation)) {
        methods.add(buildIgnoreUnknownMethod(ignorePropertiesAnnotation.ignoreUnknown()));
    }

    Optional<BeanIdentityInfo> beanIdentityInfo = Type.processIdentity(beanType);
    if(beanIdentityInfo.isPresent()){
        methods.add(buildInitIdentityInfoMethod(beanIdentityInfo.get()));
    }

    return methods;
}
 
Example #26
Source File: JsonViewSerializer.java    From json-view with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a boolean indicating whether the provided field is annotated with
 * some form of ignore. This method is memoized to speed up execution time
 */
boolean annotatedWithIgnore(AccessibleProperty f) {
  return memoizer.annotatedWithIgnore(f, () -> {
    JsonIgnore jsonIgnore = getAnnotation(f, JsonIgnore.class);
    JsonIgnoreProperties classIgnoreProperties = getAnnotation(f.declaringClass, JsonIgnoreProperties.class);
    JsonIgnoreProperties fieldIgnoreProperties = null;
    boolean backReferenced = false;

    //make sure the referring field didn't specify properties to ignore
    if(referringField != null) {
      fieldIgnoreProperties = getAnnotation(referringField, JsonIgnoreProperties.class);
    }

    //make sure the referring field didn't specify a backreference annotation
    if(getAnnotation(f, JsonBackReference.class) != null && referringField != null) {
      for(AccessibleProperty lastField : getAccessibleProperties(referringField.declaringClass)) {
        JsonManagedReference fieldManagedReference = getAnnotation(lastField, JsonManagedReference.class);
        if(fieldManagedReference != null && lastField.type.equals(f.declaringClass)) {
          backReferenced = true;
          break;
        }
      }
    }

    return (jsonIgnore != null && jsonIgnore.value()) ||
        (classIgnoreProperties != null && asList(classIgnoreProperties.value()).contains(f.name)) ||
        (fieldIgnoreProperties != null && asList(fieldIgnoreProperties.value()).contains(f.name)) ||
        backReferenced;
  });
}
 
Example #27
Source File: MasterDescription.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public MasterDescription(
        @JsonProperty(JSON_PROP_HOSTNAME) String hostname,
        @JsonProperty(JSON_PROP_HOST_IP) String hostIP,
        @JsonProperty(JSON_PROP_API_PORT) int apiPort,
        @JsonProperty(JSON_PROP_API_STATUS_URI) String apiStatusUri,
        @JsonProperty(JSON_PROP_CREATE_TIME) long createTime
) {
    this.hostname = hostname;
    this.hostIP = hostIP;
    this.apiPort = apiPort;
    this.apiStatusUri = apiStatusUri;
    this.createTime = createTime;
}
 
Example #28
Source File: AuditLogEvent.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public AuditLogEvent(
        @JsonProperty("type") Type type,
        @JsonProperty("operand") String operand,
        @JsonProperty("data") String data,
        @JsonProperty("time") long time) {
    this.type = type;
    this.operand = operand;
    this.data = data;
    this.time = time;
    this.sourceRef = Optional.empty();
}
 
Example #29
Source File: AnnotationIntrospectorPair.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated a)
{
    JsonIgnoreProperties.Value v2 = _secondary.findPropertyIgnorals(a);
    JsonIgnoreProperties.Value v1 = _primary.findPropertyIgnorals(a);
    return (v2 == null) // shouldn't occur but
        ? v1 : v2.withOverrides(v1);
}
 
Example #30
Source File: IgnorePropertyOnDeser1217Test.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testIgnoreViaConfigOverride() throws Exception
{
    ObjectMapper mapper = afterburnerMapperBuilder()
            .withConfigOverride(Point.class,
                    o -> o.setIgnorals(JsonIgnoreProperties.Value.forIgnoredProperties("y")))
            .build();
    Point p = mapper.readValue(aposToQuotes("{'x':1,'y':2}"), Point.class);
    // bind 'x', but ignore 'y'
    assertEquals(1, p.x);
    assertEquals(0, p.y);
}