Package com.knappsack.swagger4springweb.util

Source Code of com.knappsack.swagger4springweb.util.ScalaObjectMapper

package com.knappsack.swagger4springweb.util;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.module.scala.DefaultScalaModule;
import com.wordnik.swagger.model.AllowableListValues;
import com.wordnik.swagger.model.AllowableValues;

import java.io.IOException;
import java.util.ArrayList;

@SuppressWarnings("unused")
public class ScalaObjectMapper extends ObjectMapper {

    public ScalaObjectMapper() {
        registerModule(new DefaultScalaModule());
    }

    class AllowableValuesDeserializer extends StdScalarDeserializer<AllowableValues> {

        protected AllowableValuesDeserializer() {
            super(AllowableValues.class);
        }

        @Override
        public AllowableValues deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {

            String currentName = jp.getCurrentName();
            if (currentName.equalsIgnoreCase("AllowableValues")) {
                if (jp.getText().isEmpty() || jp.getText().equals("{}") || jp.getText().equals("{")) {
                    return new AllowableListValues(JavaToScalaUtil.toScalaList(new ArrayList<String>()), "");
                }
            }
            return new AllowableListValues(JavaToScalaUtil.toScalaList(new ArrayList<String>()), "");
        }
    }

}
TOP

Related Classes of com.knappsack.swagger4springweb.util.ScalaObjectMapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.