Skip to content

Commit

Permalink
Update object-into-string adapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
RezzedUp committed Jul 15, 2021
1 parent b18ba24 commit da91dca
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/com/rezzedup/util/valuables/Adapts.java
Expand Up @@ -38,15 +38,24 @@ public class Adapts

/**
* Gets standard adapters for serialized strings.
* Strings will be parsed for deserialized values.
* <p>Strings will be parsed into deserialized values.</p>
*
* @return adapters for strings
*/
public static Adapter.StandardSet<String> string() { return STRINGS; }

/**
* Gets standard adapters for casting objects.
* Objects will be cast for deserialized values.
*
* <p>Objects will be cast into deserialized values,
* with a few exceptions:</p>
*
* <ul>
* <li>{@code intoString()} converts objects into
* their string representation.</li>
* <li>All number types are compatible with each
* other since they all extend {@code Number}.</li>
* </ul>
*
* @return adapters for objects
*/
Expand Down Expand Up @@ -152,7 +161,7 @@ public <E extends Enum<E>> Adapter<String, E> intoEnum(Class<E> type)

private static class StandardObjectAdapters implements Adapter.StandardSet<Object>
{
static final Adapter<Object, String> STRING = Adapter.cast(o -> o instanceof String);
static final Adapter<Object, String> STRING = Adapter.of(o -> Optional.of(String.valueOf(o)), Optional::of);

static final Adapter<Object, Boolean> BOOLEAN = Adapter.cast(o -> o instanceof Boolean);

Expand Down

0 comments on commit da91dca

Please sign in to comment.