@Test public void emptySecureIdentifiableSerializationTest() throws Exception { serializer.serialize(new SecuredTestBean(), jsonGenerator, null); verify(jsonGenerator, times(1)).writeFieldName("isSecure"); verify(jsonGenerator, times(1)).writeFieldName("id"); verify(jsonGenerator).writeFieldName("otherAttr"); verify(jsonGenerator).writeFieldName("otherAttr2"); verify(jsonGenerator, times(4)).writeFieldName(anyString()); verify(jsonGenerator, times(3)).writeObject(null); verify(jsonGenerator, times(1)).writeObject(true); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { jsonGen = jgen; jsonProvider = provider; boolean flushEnabled = jsonGen.isEnabled(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.disable(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.writeStartObject(); if (delegatedSerializer != null) { String secureIdName = null; Object value = null; if (object instanceof SecureIdentifiable<?>) { if (delegatedSerializer instanceof ContextualSerializer) { secureIdName = "id"; value = ((SecureIdentifiable) object).getId(); try { Field identifiableField = getIdentityField(object); JsonSerializer<Object> efective = (JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, null, identifiableField != null ? identifiableField.getType() : null)); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } catch (Exception e) { } } } else if (object instanceof SecureIdContainer) { for (Field field : object.getClass().getDeclaredFields()) { TrustAssertion trustAssertion = field.getAnnotation(TrustAssertion.class); if (trustAssertion != null) { if (delegatedSerializer instanceof ContextualSerializer) { try { field.setAccessible(true); secureIdName = field.getName(); value = field.get(object); if (delegatedSerializer instanceof ContextualSerializer) { JsonSerializer<Object> efective = ((JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, trustAssertion, field.getType()))); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } } catch (Exception e) { } } } } } } writeBody(object); if (flushEnabled) { jsonGen.enable(Feature.FLUSH_PASSED_TO_STREAM); } jsonGen.writeEndObject(); }
CustomSecureSerializer extends JsonSerializer<Object> { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { jsonGen = jgen; jsonProvider = provider; boolean flushEnabled = jsonGen.isEnabled(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.disable(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.writeStartObject(); if (delegatedSerializer != null) { String secureIdName = null; Object value = null; if (object instanceof SecureIdentifiable<?>) { if (delegatedSerializer instanceof ContextualSerializer) { secureIdName = "id"; value = ((SecureIdentifiable) object).getId(); try { Field identifiableField = getIdentityField(object); JsonSerializer<Object> efective = (JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, null, identifiableField != null ? identifiableField.getType() : null)); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } catch (Exception e) { } } } else if (object instanceof SecureIdContainer) { for (Field field : object.getClass().getDeclaredFields()) { TrustAssertion trustAssertion = field.getAnnotation(TrustAssertion.class); if (trustAssertion != null) { if (delegatedSerializer instanceof ContextualSerializer) { try { field.setAccessible(true); secureIdName = field.getName(); value = field.get(object); if (delegatedSerializer instanceof ContextualSerializer) { JsonSerializer<Object> efective = ((JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, trustAssertion, field.getType()))); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } } catch (Exception e) { } } } } } } writeBody(object); if (flushEnabled) { jsonGen.enable(Feature.FLUSH_PASSED_TO_STREAM); } jsonGen.writeEndObject(); } }
CustomSecureSerializer extends JsonSerializer<Object> { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { jsonGen = jgen; jsonProvider = provider; boolean flushEnabled = jsonGen.isEnabled(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.disable(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.writeStartObject(); if (delegatedSerializer != null) { String secureIdName = null; Object value = null; if (object instanceof SecureIdentifiable<?>) { if (delegatedSerializer instanceof ContextualSerializer) { secureIdName = "id"; value = ((SecureIdentifiable) object).getId(); try { Field identifiableField = getIdentityField(object); JsonSerializer<Object> efective = (JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, null, identifiableField != null ? identifiableField.getType() : null)); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } catch (Exception e) { } } } else if (object instanceof SecureIdContainer) { for (Field field : object.getClass().getDeclaredFields()) { TrustAssertion trustAssertion = field.getAnnotation(TrustAssertion.class); if (trustAssertion != null) { if (delegatedSerializer instanceof ContextualSerializer) { try { field.setAccessible(true); secureIdName = field.getName(); value = field.get(object); if (delegatedSerializer instanceof ContextualSerializer) { JsonSerializer<Object> efective = ((JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, trustAssertion, field.getType()))); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } } catch (Exception e) { } } } } } } writeBody(object); if (flushEnabled) { jsonGen.enable(Feature.FLUSH_PASSED_TO_STREAM); } jsonGen.writeEndObject(); }  }
CustomSecureSerializer extends JsonSerializer<Object> { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { jsonGen = jgen; jsonProvider = provider; boolean flushEnabled = jsonGen.isEnabled(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.disable(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.writeStartObject(); if (delegatedSerializer != null) { String secureIdName = null; Object value = null; if (object instanceof SecureIdentifiable<?>) { if (delegatedSerializer instanceof ContextualSerializer) { secureIdName = "id"; value = ((SecureIdentifiable) object).getId(); try { Field identifiableField = getIdentityField(object); JsonSerializer<Object> efective = (JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, null, identifiableField != null ? identifiableField.getType() : null)); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } catch (Exception e) { } } } else if (object instanceof SecureIdContainer) { for (Field field : object.getClass().getDeclaredFields()) { TrustAssertion trustAssertion = field.getAnnotation(TrustAssertion.class); if (trustAssertion != null) { if (delegatedSerializer instanceof ContextualSerializer) { try { field.setAccessible(true); secureIdName = field.getName(); value = field.get(object); if (delegatedSerializer instanceof ContextualSerializer) { JsonSerializer<Object> efective = ((JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, trustAssertion, field.getType()))); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } } catch (Exception e) { } } } } } } writeBody(object); if (flushEnabled) { jsonGen.enable(Feature.FLUSH_PASSED_TO_STREAM); } jsonGen.writeEndObject(); }  void setDelegatedSerializer(final JsonSerializer<Object> delegatedSerializer); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider); }
CustomSecureSerializer extends JsonSerializer<Object> { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { jsonGen = jgen; jsonProvider = provider; boolean flushEnabled = jsonGen.isEnabled(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.disable(Feature.FLUSH_PASSED_TO_STREAM); jsonGen.writeStartObject(); if (delegatedSerializer != null) { String secureIdName = null; Object value = null; if (object instanceof SecureIdentifiable<?>) { if (delegatedSerializer instanceof ContextualSerializer) { secureIdName = "id"; value = ((SecureIdentifiable) object).getId(); try { Field identifiableField = getIdentityField(object); JsonSerializer<Object> efective = (JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, null, identifiableField != null ? identifiableField.getType() : null)); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } catch (Exception e) { } } } else if (object instanceof SecureIdContainer) { for (Field field : object.getClass().getDeclaredFields()) { TrustAssertion trustAssertion = field.getAnnotation(TrustAssertion.class); if (trustAssertion != null) { if (delegatedSerializer instanceof ContextualSerializer) { try { field.setAccessible(true); secureIdName = field.getName(); value = field.get(object); if (delegatedSerializer instanceof ContextualSerializer) { JsonSerializer<Object> efective = ((JsonSerializer<Object>) ((ContextualSerializer) delegatedSerializer) .createContextual(provider, getBeanProperty(secureIdName, value, trustAssertion, field.getType()))); secureIdSerializer.put(secureIdName, efective); if (jsonGen.getCurrentValue() == null) { jsonGen.setCurrentValue(object); } } } catch (Exception e) { } } } } } } writeBody(object); if (flushEnabled) { jsonGen.enable(Feature.FLUSH_PASSED_TO_STREAM); } jsonGen.writeEndObject(); }  void setDelegatedSerializer(final JsonSerializer<Object> delegatedSerializer); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override final void serialize(final Object object, final JsonGenerator jgen, final SerializerProvider provider);  }