Skip to content

Commit

Permalink
Merge pull request #17 from komamitsu/add-ci
Browse files Browse the repository at this point in the history
Add CI
  • Loading branch information
komamitsu authored Jan 20, 2024
2 parents 60ad29d + 61a7c8b commit aaaf272
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 178 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java_version: [11, 17]
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java_version }}
- name: Setup and execute Gradle 'check' task
uses: gradle/gradle-build-action@v2
with:
arguments: check
- name: Upload Gradle test reports
uses: actions/upload-artifact@v3
with:
name: gradle_test_reports
path: build/reports/tests/test

Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,46 @@
import retrofit2.Converter;
import retrofit2.Retrofit;

public class MessagePackConverterFactory
extends Converter.Factory
{
public static MessagePackConverterFactory create()
{
return create(new ObjectMapper(new MessagePackFactory()));
public class MessagePackConverterFactory extends Converter.Factory {
public static MessagePackConverterFactory create() {
return create(new ObjectMapper(new MessagePackFactory()));
}

@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static MessagePackConverterFactory create(ObjectMapper mapper) {
if (mapper == null) {
throw new IllegalArgumentException("'mapper' is null");
}

@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static MessagePackConverterFactory create(ObjectMapper mapper)
{
if (mapper == null) {
throw new IllegalArgumentException("'mapper' is null");
}

if (!(mapper.getFactory() instanceof MessagePackFactory)) {
throw new IllegalArgumentException("'mapper' doesn't have MessagePackFactory");
}

return new MessagePackConverterFactory(mapper);
}

private final ObjectMapper mapper;

private MessagePackConverterFactory(ObjectMapper mapper)
{
this.mapper = mapper;
}

@Override
public Converter<?, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit)
{
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectWriter writer = mapper.writerFor(javaType);
return new MessagePackRequestBodyConverter<>(writer);
if (!(mapper.getFactory() instanceof MessagePackFactory)) {
throw new IllegalArgumentException("'mapper' doesn't have MessagePackFactory");
}

@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type,
Annotation[] annotations, Retrofit retrofit)
{
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader reader = mapper.readerFor(javaType);
return new MessagePackResponseBodyConverter<>(reader);
}
return new MessagePackConverterFactory(mapper);
}

private final ObjectMapper mapper;

private MessagePackConverterFactory(ObjectMapper mapper) {
this.mapper = mapper;
}

@Override
public Converter<?, RequestBody> requestBodyConverter(
Type type,
Annotation[] parameterAnnotations,
Annotation[] methodAnnotations,
Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectWriter writer = mapper.writerFor(javaType);
return new MessagePackRequestBodyConverter<>(writer);
}

@Override
public Converter<ResponseBody, ?> responseBodyConverter(
Type type, Annotation[] annotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader reader = mapper.readerFor(javaType);
return new MessagePackResponseBodyConverter<>(reader);
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package org.komamitsu.retrofit.converter.msgpack;

import com.fasterxml.jackson.databind.ObjectWriter;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Converter;

import java.io.IOException;

class MessagePackRequestBodyConverter<T>
implements Converter<T, RequestBody>
{
private static final MediaType MEDIA_TYPE = MediaType.parse("application/x-msgpack; charset=UTF-8");
class MessagePackRequestBodyConverter<T> implements Converter<T, RequestBody> {
private static final MediaType MEDIA_TYPE =
MediaType.parse("application/x-msgpack; charset=UTF-8");

private final ObjectWriter adapter;
private final ObjectWriter adapter;

MessagePackRequestBodyConverter(ObjectWriter adapter)
{
this.adapter = adapter;
}
MessagePackRequestBodyConverter(ObjectWriter adapter) {
this.adapter = adapter;
}

@Override
public RequestBody convert(T value)
throws IOException
{
byte[] bytes = adapter.writeValueAsBytes(value);
return RequestBody.create(MEDIA_TYPE, bytes);
}
@Override
public RequestBody convert(T value) throws IOException {
byte[] bytes = adapter.writeValueAsBytes(value);
return RequestBody.create(MEDIA_TYPE, bytes);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package org.komamitsu.retrofit.converter.msgpack;

import com.fasterxml.jackson.databind.ObjectReader;
import okhttp3.ResponseBody;
import retrofit2.Converter;

import java.io.IOException;
import java.io.InputStream;
import okhttp3.ResponseBody;
import retrofit2.Converter;

class MessagePackResponseBodyConverter<T>
implements Converter<ResponseBody, T>
{
private final ObjectReader adapter;
class MessagePackResponseBodyConverter<T> implements Converter<ResponseBody, T> {
private final ObjectReader adapter;

MessagePackResponseBodyConverter(ObjectReader adapter)
{
this.adapter = adapter;
}
MessagePackResponseBodyConverter(ObjectReader adapter) {
this.adapter = adapter;
}

@Override
public T convert(ResponseBody value) throws IOException
{
try (InputStream in = value.byteStream()) {
return adapter.readValue(in);
}
@Override
public T convert(ResponseBody value) throws IOException {
try (InputStream in = value.byteStream()) {
return adapter.readValue(in);
}
}
}
Loading

0 comments on commit aaaf272

Please sign in to comment.