package com.github.nsnjson.decoding;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;

import java.util.Optional;

public abstract class AbstractDecoding implements Decoding {

    @Override
    public Optional<JsonNode> decode(JsonNode presentation) {
        Optional<JsonNodeType> typeOption = getType(presentation);

        if (typeOption.isPresent()) {
            JsonNodeType type = typeOption.get();

            switch (type) {
                case NULL:    return decodeNull();
                case NUMBER:  return decodeNumber(presentation);
                case STRING:  return decodeString(presentation);
                case BOOLEAN: return decodeBoolean(presentation);
                case ARRAY:   return decodeArray(presentation);
                case OBJECT:  return decodeObject(presentation);
            }
        }

        return Optional.empty();
    }

}
@@ -82,65 +82,8 @@
 ode;
-%0Aimport com.fasterxml.jackson.databind.node.JsonNodeType;
 %0A%0Aim
@@ -258,156 +258,54 @@
     
-Optional%3CJsonNodeType%3E typeOption = getType(presentation);%0A%0A        if (typeOption.isPresent()) %7B%0A            JsonNodeType type = typeOption.get();%0A
+return getType(presentation).flatMap(type -%3E %7B
 %0A   
@@ -717,17 +717,28 @@
         
-%7D
+    default:
 %0A       
@@ -738,19 +738,20 @@
         
-%7D%0A%0A
+    
         
@@ -771,20 +771,46 @@
 al.empty();%0A
+            %7D%0A        %7D);%0A
     %7D%0A%0A%7D

Refactor method { AbstractDecoding @ getType }