From e1053dc90c15ecf616c831eba6cde5de80f47634 Mon Sep 17 00:00:00 2001 From: anttil <anttil> Date: Mon, 25 Feb 2013 13:20:25 +0000 Subject: [PATCH] Whitelist for classes for which duplicate @JsonTypeName value is allowed. SVN: 28442 --- .../server/json/JsonUniqueCheckIgnore.java | 34 ------------------- .../object/ObjectWithTypeALegalDuplicate.java | 2 -- .../ObjectWithTypeBIllegalDuplicate.java | 2 -- .../systemtests/JsonAnnotationTest.java | 17 ++++++---- 4 files changed, 11 insertions(+), 44 deletions(-) delete mode 100644 openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/JsonUniqueCheckIgnore.java diff --git a/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/JsonUniqueCheckIgnore.java b/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/JsonUniqueCheckIgnore.java deleted file mode 100644 index 627d3cb014a..00000000000 --- a/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/JsonUniqueCheckIgnore.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012 ETH Zuerich, CISD - * - * 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 ch.systemsx.cisd.openbis.common.api.server.json; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * If a class is annotated with JsonUniqueCheckIgnore, the JsonAnnotationTest will not complain - * about it having a duplicate JsonTypeName. - * - * @author anttil - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface JsonUniqueCheckIgnore -{ -} diff --git a/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeALegalDuplicate.java b/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeALegalDuplicate.java index f567800e100..d732979bfa3 100644 --- a/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeALegalDuplicate.java +++ b/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeALegalDuplicate.java @@ -4,7 +4,6 @@ import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import ch.systemsx.cisd.base.annotation.JsonObject; -import ch.systemsx.cisd.openbis.common.api.server.json.JsonUniqueCheckIgnore; /* * Copyright 2012 ETH Zuerich, CISD @@ -25,7 +24,6 @@ import ch.systemsx.cisd.openbis.common.api.server.json.JsonUniqueCheckIgnore; /** * @author pkupczyk */ -@JsonUniqueCheckIgnore @JsonObject(ObjectWithTypeAFactory.TYPE) public class ObjectWithTypeALegalDuplicate { diff --git a/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeBIllegalDuplicate.java b/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeBIllegalDuplicate.java index c1c1206b139..b3cc61834b6 100644 --- a/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeBIllegalDuplicate.java +++ b/openbis-common/sourceTest/java/ch/systemsx/cisd/openbis/common/api/server/json/object/ObjectWithTypeBIllegalDuplicate.java @@ -4,7 +4,6 @@ import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import ch.systemsx.cisd.base.annotation.JsonObject; -import ch.systemsx.cisd.openbis.common.api.server.json.JsonUniqueCheckIgnore; /* * Copyright 2012 ETH Zuerich, CISD @@ -26,7 +25,6 @@ import ch.systemsx.cisd.openbis.common.api.server.json.JsonUniqueCheckIgnore; * @author pkupczyk */ @JsonObject(ObjectWithTypeBFactory.TYPE) -@JsonUniqueCheckIgnore public class ObjectWithTypeBIllegalDuplicate extends ObjectWithType { diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/JsonAnnotationTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/JsonAnnotationTest.java index 3b940da0cc2..87f6bde48e8 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/JsonAnnotationTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/JsonAnnotationTest.java @@ -31,7 +31,6 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import ch.systemsx.cisd.base.annotation.JsonObject; -import ch.systemsx.cisd.openbis.common.api.server.json.JsonUniqueCheckIgnore; import ch.systemsx.cisd.openbis.common.api.server.json.util.ClassReferences; import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric; import ch.systemsx.cisd.openbis.dss.screening.shared.api.v1.IDssServiceRpcScreening; @@ -91,16 +90,22 @@ public class JsonAnnotationTest @Test public void jsonTypeNamesAreUnique() { + // Classes that are allowed to have already existing @JsonTypeName + Collection<String> whiteList = new HashSet<String>(); + whiteList + .add("ch.systemsx.cisd.openbis.common.api.server.json.object.ObjectWithTypeALegalDuplicate"); + whiteList + .add("ch.systemsx.cisd.openbis.common.api.server.json.object.ObjectWithTypeBIllegalDuplicate"); + whiteList.add("ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ExperimentIdentifier"); + Map<String, Collection<Class<?>>> names = new HashMap<String, Collection<Class<?>>>(); for (Class<?> clazz : ClassReferences.ref.getTypesAnnotatedWith(JsonObject.class)) { - if (clazz.getAnnotation(JsonUniqueCheckIgnore.class) != null) + if (whiteList.contains(clazz.getCanonicalName()) == false) { - continue; + String name = clazz.getAnnotation(JsonObject.class).value(); + addValueToCollectionMap(names, name, clazz); } - - String name = clazz.getAnnotation(JsonObject.class).value(); - addValueToCollectionMap(names, name, clazz); } assertThat(duplicatedValuesIn(names), is(emptyMap)); -- GitLab