@Test public void serialize( @Mock JsonGenerator jgen, @Mock SerializerProvider sp) throws IOException { serializer.serialize(new GuardedString(), jgen, sp); verify(jgen).writeBooleanField(READONLY, false); verify(jgen).writeBooleanField(DISPOSED, false); verify(jgen).writeStringField(eq(ENCRYPTED_BYTES), anyString()); verify(jgen).writeStringField(eq(BASE64_SHA1_HASH), anyString()); verify(jgen).writeEndObject(); }
@Override public void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); boolean readOnly = false; try { Field field = GuardedString.class.getDeclaredField(READONLY); ReflectionUtils.makeAccessible(field); readOnly = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(READONLY, readOnly); boolean disposed = false; try { Field field = GuardedString.class.getDeclaredField(DISPOSED); ReflectionUtils.makeAccessible(field); disposed = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(DISPOSED, disposed); byte[] encryptedBytes = EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField(ENCRYPTED_BYTES, Base64.getEncoder().encodeToString(encryptedBytes)); String base64SHA1Hash = null; try { Field field = GuardedString.class.getDeclaredField(BASE64_SHA1_HASH); ReflectionUtils.makeAccessible(field); base64SHA1Hash = field.get(source).toString(); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } if (base64SHA1Hash != null) { jgen.writeStringField(BASE64_SHA1_HASH, base64SHA1Hash); } jgen.writeEndObject(); }
GuardedStringSerializer extends JsonSerializer<GuardedString> { @Override public void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); boolean readOnly = false; try { Field field = GuardedString.class.getDeclaredField(READONLY); ReflectionUtils.makeAccessible(field); readOnly = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(READONLY, readOnly); boolean disposed = false; try { Field field = GuardedString.class.getDeclaredField(DISPOSED); ReflectionUtils.makeAccessible(field); disposed = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(DISPOSED, disposed); byte[] encryptedBytes = EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField(ENCRYPTED_BYTES, Base64.getEncoder().encodeToString(encryptedBytes)); String base64SHA1Hash = null; try { Field field = GuardedString.class.getDeclaredField(BASE64_SHA1_HASH); ReflectionUtils.makeAccessible(field); base64SHA1Hash = field.get(source).toString(); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } if (base64SHA1Hash != null) { jgen.writeStringField(BASE64_SHA1_HASH, base64SHA1Hash); } jgen.writeEndObject(); } }
GuardedStringSerializer extends JsonSerializer<GuardedString> { @Override public void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); boolean readOnly = false; try { Field field = GuardedString.class.getDeclaredField(READONLY); ReflectionUtils.makeAccessible(field); readOnly = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(READONLY, readOnly); boolean disposed = false; try { Field field = GuardedString.class.getDeclaredField(DISPOSED); ReflectionUtils.makeAccessible(field); disposed = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(DISPOSED, disposed); byte[] encryptedBytes = EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField(ENCRYPTED_BYTES, Base64.getEncoder().encodeToString(encryptedBytes)); String base64SHA1Hash = null; try { Field field = GuardedString.class.getDeclaredField(BASE64_SHA1_HASH); ReflectionUtils.makeAccessible(field); base64SHA1Hash = field.get(source).toString(); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } if (base64SHA1Hash != null) { jgen.writeStringField(BASE64_SHA1_HASH, base64SHA1Hash); } jgen.writeEndObject(); }  }
GuardedStringSerializer extends JsonSerializer<GuardedString> { @Override public void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); boolean readOnly = false; try { Field field = GuardedString.class.getDeclaredField(READONLY); ReflectionUtils.makeAccessible(field); readOnly = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(READONLY, readOnly); boolean disposed = false; try { Field field = GuardedString.class.getDeclaredField(DISPOSED); ReflectionUtils.makeAccessible(field); disposed = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(DISPOSED, disposed); byte[] encryptedBytes = EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField(ENCRYPTED_BYTES, Base64.getEncoder().encodeToString(encryptedBytes)); String base64SHA1Hash = null; try { Field field = GuardedString.class.getDeclaredField(BASE64_SHA1_HASH); ReflectionUtils.makeAccessible(field); base64SHA1Hash = field.get(source).toString(); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } if (base64SHA1Hash != null) { jgen.writeStringField(BASE64_SHA1_HASH, base64SHA1Hash); } jgen.writeEndObject(); }  @Override void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp); }
GuardedStringSerializer extends JsonSerializer<GuardedString> { @Override public void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp) throws IOException { jgen.writeStartObject(); boolean readOnly = false; try { Field field = GuardedString.class.getDeclaredField(READONLY); ReflectionUtils.makeAccessible(field); readOnly = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(READONLY, readOnly); boolean disposed = false; try { Field field = GuardedString.class.getDeclaredField(DISPOSED); ReflectionUtils.makeAccessible(field); disposed = field.getBoolean(source); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } jgen.writeBooleanField(DISPOSED, disposed); byte[] encryptedBytes = EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(SecurityUtil.decrypt(source).getBytes()); jgen.writeStringField(ENCRYPTED_BYTES, Base64.getEncoder().encodeToString(encryptedBytes)); String base64SHA1Hash = null; try { Field field = GuardedString.class.getDeclaredField(BASE64_SHA1_HASH); ReflectionUtils.makeAccessible(field); base64SHA1Hash = field.get(source).toString(); } catch (Exception e) { LOG.error(LOG_ERROR_MESSAGE, e); } if (base64SHA1Hash != null) { jgen.writeStringField(BASE64_SHA1_HASH, base64SHA1Hash); } jgen.writeEndObject(); }  @Override void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp);  }