Created
February 27, 2016 01:22
-
-
Save fehguy/00fa199128876a5f5afb to your computer and use it in GitHub Desktop.
override example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.swagger.model.override; | |
import com.fasterxml.jackson.databind.JavaType; | |
import io.swagger.converter.ModelConverter; | |
import io.swagger.converter.ModelConverterContext; | |
import io.swagger.models.Model; | |
import io.swagger.models.properties.*; | |
import io.swagger.util.Json; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.Type; | |
import java.util.Iterator; | |
/** | |
* Sample converter implementation which turns "MyCustomClass" into a DateTime property | |
*/ | |
public class SamplePropertyConverter implements ModelConverter { | |
@Override | |
public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { | |
JavaType _type = Json.mapper().constructType(type); | |
if (_type != null) { | |
Class<?> cls = _type.getRawClass(); | |
if (java.util.Date.class.isAssignableFrom(cls)) { | |
return new LongProperty(); | |
} | |
} | |
if (chain.hasNext()) { | |
return chain.next().resolveProperty(type, context, annotations, chain); | |
} else { | |
return null; | |
} | |
} | |
@Override | |
public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { | |
if (chain.hasNext()) { | |
return chain.next().resolve(type, context, chain); | |
} else { | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
testing with this:
and this pojo:
Does the right thing: