Search in sources :

Example 1 with JacksonEncoder

use of feign.jackson.JacksonEncoder in project nutzboot by nutzam.

the class FeignStarter method getEncoder.

protected Encoder getEncoder(FeignInject fc, Field field) {
    String encoderStr = Strings.sBlank(fc.encoder(), conf.get(PROP_ENCODER, ""));
    switch(encoderStr) {
        case "":
        case "raw":
            break;
        case "nutzjson":
            JsonFormat jf = JsonFormat.full();
            String jfStr = Strings.sBlank(fc.jsonFormat(), conf.get(PROP_JSON_FORMAT, ""));
            if (!Strings.isBlank(jfStr)) {
                if (jfStr.startsWith("{")) {
                    jf = Json.fromJson(JsonFormat.class, jfStr);
                } else if (jfStr.startsWith("ioc:")) {
                    jf = ioc.get(JsonFormat.class, jfStr.substring(4));
                } else {
                    try {
                        jf = (JsonFormat) JsonFormat.class.getMethod(jfStr).invoke(null);
                    } catch (Exception e) {
                        log.infof("invaild JsonFormat=[%s] at %s", jfStr, field);
                    }
                }
            }
            return new NutzJsonEncoder(jf);
        case "jackson":
            return new JacksonEncoder();
        case "gson":
            return new GsonEncoder();
        case "jaxb":
            JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder().withMarshallerJAXBEncoding("UTF-8").withMarshallerSchemaLocation(getSchemaString(fc.schema())).build();
            return new JAXBEncoder(jaxbFactory);
        default:
            if (encoderStr.startsWith("ioc"))
                return ioc.get(Encoder.class, encoderStr.substring(4));
            break;
    }
    return null;
}
Also used : JAXBContextFactory(feign.jaxb.JAXBContextFactory) JsonFormat(org.nutz.json.JsonFormat) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) Encoder(feign.codec.Encoder) JacksonEncoder(feign.jackson.JacksonEncoder) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) JacksonEncoder(feign.jackson.JacksonEncoder)

Example 2 with JacksonEncoder

use of feign.jackson.JacksonEncoder in project atlasdb by palantir.

the class TimestampRemotingTest method testNotLeader.

@Test
public void testNotLeader() {
    ObjectMapper mapper = new ObjectMapper();
    String uri = notLeader.baseUri().toString();
    TimestampService ts = Feign.builder().decoder(new JacksonDecoder(mapper)).encoder(new JacksonEncoder(mapper)).contract(new JAXRSContract()).retryer(new Retryer.Default(1, 1, 40)).target(TimestampService.class, notLeader.baseUri().toString());
    ts.getFreshTimestamp();
}
Also used : JacksonEncoder(feign.jackson.JacksonEncoder) JAXRSContract(feign.jaxrs.JAXRSContract) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) JacksonDecoder(feign.jackson.JacksonDecoder) Test(org.junit.Test)

Example 3 with JacksonEncoder

use of feign.jackson.JacksonEncoder in project atlasdb by palantir.

the class TimestampRemotingTest method testSerializing.

@Test
public void testSerializing() {
    ObjectMapper mapper = new ObjectMapper();
    String uri = dropwizard.baseUri().toString();
    TimestampService ts = Feign.builder().decoder(new JacksonDecoder(mapper)).encoder(new JacksonEncoder(mapper)).contract(new JAXRSContract()).target(TimestampService.class, uri);
    long freshTimestamp = ts.getFreshTimestamp();
    TimestampRange freshTimestamps = ts.getFreshTimestamps(100);
}
Also used : JacksonEncoder(feign.jackson.JacksonEncoder) JAXRSContract(feign.jaxrs.JAXRSContract) TimestampRange(com.palantir.timestamp.TimestampRange) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) JacksonDecoder(feign.jackson.JacksonDecoder) Test(org.junit.Test)

Example 4 with JacksonEncoder

use of feign.jackson.JacksonEncoder in project feign by OpenFeign.

the class ReactiveFeignIntegrationTest method testRxJavaTarget.

@Test
public void testRxJavaTarget() throws Exception {
    this.webServer.enqueue(new MockResponse().setBody("1.0"));
    this.webServer.enqueue(new MockResponse().setBody("{ \"username\": \"test\" }"));
    TestReactiveXService service = RxJavaFeign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder()).logger(new ConsoleLogger()).logLevel(Level.FULL).target(TestReactiveXService.class, this.getServerUrl());
    assertThat(service).isNotNull();
    StepVerifier.create(service.version()).expectNext("1.0").expectComplete().verify();
    assertThat(webServer.takeRequest().getPath()).isEqualToIgnoringCase("/version");
    /* test encoding and decoding */
    StepVerifier.create(service.user("test")).assertNext(user -> assertThat(user).hasFieldOrPropertyWithValue("username", "test")).expectComplete().verify();
    assertThat(webServer.takeRequest().getPath()).isEqualToIgnoringCase("/users/test");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JacksonEncoder(feign.jackson.JacksonEncoder) JacksonDecoder(feign.jackson.JacksonDecoder) Test(org.junit.Test)

Example 5 with JacksonEncoder

use of feign.jackson.JacksonEncoder in project feign by OpenFeign.

the class ReactiveFeignIntegrationTest method testReactorTargetFull.

@Test
public void testReactorTargetFull() throws Exception {
    this.webServer.enqueue(new MockResponse().setBody("1.0"));
    this.webServer.enqueue(new MockResponse().setBody("{ \"username\": \"test\" }"));
    TestReactorService service = ReactorFeign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder()).logger(new ConsoleLogger()).decode404().options(new Options()).logLevel(Level.FULL).target(TestReactorService.class, this.getServerUrl());
    assertThat(service).isNotNull();
    StepVerifier.create(service.version()).expectNext("1.0").expectComplete().verify();
    assertThat(webServer.takeRequest().getPath()).isEqualToIgnoringCase("/version");
    /* test encoding and decoding */
    StepVerifier.create(service.user("test")).assertNext(user -> assertThat(user).hasFieldOrPropertyWithValue("username", "test")).expectComplete().verify();
    assertThat(webServer.takeRequest().getPath()).isEqualToIgnoringCase("/users/test");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Options(feign.Request.Options) JacksonEncoder(feign.jackson.JacksonEncoder) JacksonDecoder(feign.jackson.JacksonDecoder) Test(org.junit.Test)

Aggregations

JacksonEncoder (feign.jackson.JacksonEncoder)9 JacksonDecoder (feign.jackson.JacksonDecoder)8 Test (org.junit.Test)4 JAXRSContract (feign.jaxrs.JAXRSContract)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FeignTransactionClient (com.github.rosklyar.client.transaction.FeignTransactionClient)2 SecureTransactionClient (com.github.rosklyar.client.transaction.SecureTransactionClient)2 DefaultFeeCalculator (com.github.rosklyar.client.transaction.fee.DefaultFeeCalculator)2 FeeCalculator (com.github.rosklyar.client.transaction.fee.FeeCalculator)2 DefaultVersionProvider (com.github.rosklyar.client.transaction.version.DefaultVersionProvider)2 VersionProvider (com.github.rosklyar.client.transaction.version.VersionProvider)2 InMemoryTimestampService (com.palantir.timestamp.InMemoryTimestampService)2 TimestampService (com.palantir.timestamp.TimestampService)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Before (org.junit.Before)2 AtlasDbService (com.palantir.atlasdb.api.AtlasDbService)1 TimestampRange (com.palantir.timestamp.TimestampRange)1 Options (feign.Request.Options)1 Encoder (feign.codec.Encoder)1 GsonEncoder (feign.gson.GsonEncoder)1