Commit f24473b6 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'smarter-JSON-serialization-for-ui' into 'master'

Updated JSON serialization for ES

See merge request genesys-pgr/genesys-server!420
parents c3fe2afa 5e5177ed
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,18 +15,17 @@
*/
package org.genesys2.server.component.elastic;
import java.lang.annotation.Annotation;
import java.util.List;
import org.genesys.blocks.security.serialization.CurrentPermissionsWriter;
import org.genesys.custom.elasticsearch.IgnoreField;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
/**
......@@ -34,6 +33,8 @@ import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
* ES.
*
* - Ignores @Field(index = no) properties
* - Ignore @JsonIdentityInfo on classes to prevent them being serialized as ID-only
* - Ignore CurrentPermissionsWriter ("_permissions")
*
* @author Matija Obreza
* @since 1 Aug 2018
......@@ -41,22 +42,32 @@ import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
public class ElasticJacksonAnnotationIntrospector extends JacksonAnnotationIntrospector {
private static final long serialVersionUID = 6225410633030301962L;
/**
* Allows us to ignore @JsonIdentityInfo on classes to prevent them being serialized as ID-only
*/
@Override
protected boolean _hasAnnotation(Annotated annotated, Class<? extends Annotation> annoClass) {
if (JsonIdentityInfo.class.isAssignableFrom(annoClass)) {
// Completely ignore JsonIdentityInfo annotations
return false;
public ObjectIdInfo findObjectIdInfo(Annotated ann) {
if (ann instanceof AnnotatedClass) {
// Ignore @JsonIdentityInfo on classes
// System.err.println("Ignoring @JsonIdentityInfo for=" + ann);
return null;
}
return super._hasAnnotation(annotated, annoClass);
return super.findObjectIdInfo(ann);
}
/**
* We don't want to serialize _permissions property to ES
*/
@Override
public void findAndAddVirtualProperties(MapperConfig<?> config, AnnotatedClass ac, List<BeanPropertyWriter> properties) {
super.findAndAddVirtualProperties(config, ac, properties);
// Remove current permissions writer
properties.removeIf(bpw -> bpw instanceof CurrentPermissionsWriter);
}
/**
* Ignore properties where @Fileld(index = no)
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment