SecureJSON.Builder¶
-
public static final class
Builder¶ Builder for SecureJSON. This allows specifying options for the encoder and decoder to use.
Methods¶
build¶
-
public SecureJSON
build()¶ Build a SecureJSON instance using our settings.
Example:
import com.chelseaurquhart.securejson.SecureJSON; final SecureJSON secureJSON = new SecureJSON.Builder().build();
The above example is functionally equivalent to:
import com.chelseaurquhart.securejson.SecureJSON; final SecureJSON secureJSON = new SecureJSON();
Returns: A SecureJSON instance.
strictMapKeyTypes¶
-
public Builder
strictMapKeyTypes(boolean parStrictMapKeyTypes)¶ Set the strictMapKeyTypes option. If strictMapKeyTypes is true, we will never convert CharSequence to string when we are creating Maps (which require CharSequence-like keys). If false, we will try to convert the object to a string. This should be used with caution, and certainly not for sensitive data as strings may stay in memory much longer than desired.
Default: true
Example (disable strict map key types in order to allow Strings to be populated for Map keys):
import com.chelseaurquhart.securejson.SecureJSON; final SecureJSON secureJSON = new SecureJSON.Builder() .strictMapKeyTypes(false) .build();
Parameters: - parStrictMapKeyTypes – The value to use for our strict map keys setting.
Returns: A reference to this object.
strictStrings¶
-
public Builder
strictStrings(boolean parStrictStrings)¶ Set the strictStrings option. If strictStrings is true, we will never convert CharSequence to string. If it is false, we will convert if we can’t otherwise cast. Default is true. This should be used with caution, and certainly not for sensitive data as strings may stay in memory much longer than desired.
Default: true
Example (disable strict strings in order to allow Strings to be populated for non-sensitive fields):
import com.chelseaurquhart.securejson.SecureJSON; final SecureJSON secureJSON = new SecureJSON.Builder() .strictStrings(false) .build();
Parameters: - parStrictStrings – The value to use for our strict strings setting.
Returns: A reference to this object.
writableCharBufferFactory¶
-
public Builder
writableCharBufferFactory(IFunction<Integer, IWritableCharSequence> parWritableCharBufferFactory)¶ Set the factory to use for building secure buffers. By default we will use our own implementation, but this can be used to provide a custom one.
Default: <internally managed factory>
Example (use a custom IWritableCharSequence factory):
Danger
This sample implementation is by no means secure! The default, however, is.
import com.chelseaurquhart.securejson.SecureJSON; final SecureJSON secureJSON = new SecureJSON.Builder() .writableCharBufferFactory(new IFunction<Integer, IWritableCharSequence>() { @Override public IWritableCharSequence accept(final Integer parCapacity) { return new IWritableCharSequence() { private final StringBuilder builder = new StringBuilder(parCapacity); @Override public void append(char parChar) { builder.append(parCapacity); } @Override public boolean isRestrictedToCapacity() { return false; } @Override public int getCapacity() { return builder.capacity(); } @Override public void close() { builder.setLength(0); } @Override public int length() { return builder.length(); } @Override public char charAt(final int parIndex) { return builder.charAt(parIndex); } @Override public CharSequence subSequence(final int parStart, final int parEnd) { return builder.subSequence(parStart, parEnd); } }; } }) .build();
Parameters: - parWritableCharBufferFactory – The factory to use for building secure buffers.
Returns: A reference to this object.