forked from loafle/openapi-generator-original
Jaxrs jersey2 support (#5058)
* [JAVA/] jaxrs/jersey2 (Issue: 4662) Made java8-date codegeneration to work with jersey2 * Ran shellscripts for jaxrs-jersey-petstore-server and java8-petstore-jersey2 to update petstore samples
This commit is contained in:
parent
c14da15b3e
commit
9055dfc42e
@ -0,0 +1,28 @@
|
|||||||
|
package {{apiPackage}};
|
||||||
|
|
||||||
|
import javax.ws.rs.ext.ParamConverter;
|
||||||
|
import javax.ws.rs.ext.ParamConverterProvider;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
public class LocalDateProvider implements ParamConverterProvider {
|
||||||
|
|
||||||
|
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) {
|
||||||
|
if (clazz.getName().equals(LocalDate.class.getName())) {
|
||||||
|
return new ParamConverter<T>() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public T fromString(String value) {
|
||||||
|
return value!=null ? (T) LocalDate.parse(value) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(T bean) {
|
||||||
|
return bean!=null ? bean.toString() : "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package {{apiPackage}};
|
||||||
|
|
||||||
|
import javax.ws.rs.ext.ParamConverter;
|
||||||
|
import javax.ws.rs.ext.ParamConverterProvider;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
public class OffsetDateTimeProvider implements ParamConverterProvider {
|
||||||
|
|
||||||
|
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) {
|
||||||
|
if (clazz.getName().equals(OffsetDateTime.class.getName())) {
|
||||||
|
return new ParamConverter<T>() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public T fromString(String value) {
|
||||||
|
return value != null ? (T) OffsetDateTime.parse(value) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(T bean) {
|
||||||
|
return bean != null ? bean.toString() : "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
1
samples/client/petstore/java/jersey2/hello.txt
Normal file
1
samples/client/petstore/java/jersey2/hello.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello world!
|
Loading…
x
Reference in New Issue
Block a user