Java Code Examples for com.google.gson.FieldAttributes#getAnnotation()
The following examples show how to use
com.google.gson.FieldAttributes#getAnnotation() .
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: SerializationWithExclusionsUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenExclusionStrategyByCustomAnnotation_whenSerializing_thenFollowStrategy() { MyClassWithCustomAnnotatedFields source = new MyClassWithCustomAnnotatedFields(1L, "foo", "bar", new MySubClassWithCustomAnnotatedFields(42L, "the answer", "Verbose field which we don't want to be serialized")); ExclusionStrategy strategy = new ExclusionStrategy() { @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } @Override public boolean shouldSkipField(FieldAttributes field) { return field.getAnnotation(Exclude.class) != null; } }; Gson gson = new GsonBuilder().setExclusionStrategies(strategy) .create(); String jsonString = gson.toJson(source); assertEquals(expectedResult, jsonString); }
Example 2
Source File: ApiResponseGsonHelper.java From cosmic with Apache License 2.0 | 6 votes |
public boolean shouldSkipField(final FieldAttributes f) { final Param param = f.getAnnotation(Param.class); if (param != null) { final RoleType[] allowedRoles = param.authorized(); if (allowedRoles.length > 0) { boolean permittedParameter = false; final Account caller = CallContext.current().getCallingAccount(); for (final RoleType allowedRole : allowedRoles) { if (allowedRole.getValue() == caller.getType()) { permittedParameter = true; break; } } if (!permittedParameter) { return true; } } } return false; }
Example 3
Source File: ApiResponseGsonHelper.java From cloudstack with Apache License 2.0 | 5 votes |
public boolean shouldSkipField(FieldAttributes f) { Param param = f.getAnnotation(Param.class); boolean skip = (param != null && param.isSensitive()); if (!skip) { skip = super.shouldSkipField(f); } return skip; }
Example 4
Source File: JadxSettingsAdapter.java From jadx with Apache License 2.0 | 5 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return JadxSettings.SKIP_FIELDS.contains(f.getName()) || f.hasModifier(Modifier.PUBLIC) || f.hasModifier(Modifier.TRANSIENT) || (f.getAnnotation(GsonExclude.class) != null); }
Example 5
Source File: ApiResponseGsonHelper.java From cosmic with Apache License 2.0 | 5 votes |
public boolean shouldSkipField(final FieldAttributes f) { final Param param = f.getAnnotation(Param.class); boolean skip = (param != null && param.isSensitive()); if (!skip) { skip = super.shouldSkipField(f); } return skip; }
Example 6
Source File: AnnotatedStrategy.java From devicehive-java-server with Apache License 2.0 | 5 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { JsonPolicyDef policyAnnotation = f.getAnnotation(JsonPolicyDef.class); if (policyAnnotation == null) { // no policy annotation - filed should be skipped return true; } for (JsonPolicyDef.Policy definedPolicy : policyAnnotation.value()) { if (definedPolicy == policy) { // policy is found - field is to be included return false; } } return true; }
Example 7
Source File: GSONWrapper.java From Utils with Apache License 2.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(JSONNode.class) == null; }
Example 8
Source File: NonSerializableStrategy.java From CardFantasy with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(NonSerializable.class) != null; }
Example 9
Source File: PlayerSerializationFilter.java From asteria-3.0 with GNU General Public License v3.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes attr) { return attr.hasModifier(Modifier.STATIC) || attr.hasModifier(Modifier.TRANSIENT) || attr.getAnnotation(SerializationExclude.class) != null; }
Example 10
Source File: JsonUtil.java From ldbc_graphalytics with Apache License 2.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(Exclude.class) != null; }
Example 11
Source File: Utilities.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(JsonExclude.class) != null; }
Example 12
Source File: ExclusionStrategyFunctionalTest.java From gson with Apache License 2.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(Foo.class) != null; }
Example 13
Source File: AnnotationExclusionStrategy.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(Exclude.class) != null; }
Example 14
Source File: FabricGsonSerializeExclusionStrategy.java From spring-fabric-gateway with MIT License | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { FabricIgnore ignore = f.getAnnotation(FabricIgnore.class); return ignore != null && ignore.serialize(); }
Example 15
Source File: LoggingExclusionStrategy.java From cloudstack with Apache License 2.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes field) { LogLevel level = field.getAnnotation(LogLevel.class); return level != null && !level.value().enabled(_logger); }
Example 16
Source File: RequestDataJSONObjectUtil.java From zstack with Apache License 2.0 | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(GsonTransient.class) != null; }
Example 17
Source File: AnnotationExclusionStrategy.java From quill with MIT License | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(GsonExclude.class) != null; }
Example 18
Source File: JsonExclusionStrategy.java From RoomBookerMVP with MIT License | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { final Expose expose = fieldAttributes.getAnnotation(Expose.class); return expose != null && !expose.serialize(); }
Example 19
Source File: LoggingExclusionStrategy.java From cosmic with Apache License 2.0 | 4 votes |
@Override public boolean shouldSkipField(final FieldAttributes field) { final LogLevel level = field.getAnnotation(LogLevel.class); return level != null && !level.value().enabled(_logger); }
Example 20
Source File: FabricGsonDeserializeExclusionStrategy.java From spring-fabric-gateway with MIT License | 4 votes |
@Override public boolean shouldSkipField(FieldAttributes f) { FabricIgnore ignore = f.getAnnotation(FabricIgnore.class); return ignore != null && ignore.deserialize(); }