swagger-api / swagger-api/swagger-codegen

[Java] [Android] Jersey2 library request/issue - suppress warning log in android

Open
#8,450 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When I generate swagger client for java using Jersey 2 library and use it with both java and android project (which works in android), there are warning thrown by client because of use of java.awt.* class in jersey unsupported by Android. Although these are just warnings but there are way to suppress such warnings. (and maybe make jersey2 client library available for android platform?)

The main purpose of using jersey client in Android is to support circular dependency json sent by server (Jsog Jackson)

Swagger-codegen version

2.3.1, older one (with no version command)

Suggest a fix/enhancement

The way to suppress those warnings in logs is to add a feature to client that let hk2 not search for non available files.

Sample code for feature (that i am using with generated code)

import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import org.glassfish.hk2.api.Descriptor;
import org.glassfish.hk2.api.Filter;
import org.glassfish.hk2.utilities.binding.AbstractBinder;

/**
 *
 * @author akshit
 */
public class AndroidFriendlyFeature implements Feature {
    @Override
    public boolean configure(FeatureContext context) {
      context.register(new AbstractBinder() {
          @Override
          protected void configure() {
              addUnbindFilter(new Filter() {
                  @Override
                  public boolean matches(Descriptor d) {
                      String implClass = d.getImplementation();
                      return implClass.startsWith("org.glassfish.jersey.message.internal.DataSource")
                       || implClass.startsWith("org.glassfish.jersey.message.internal.RenderedImage");
                  }
              });
          }
      });
      return true;
    }
}

then add it to client on ApiClient.java buildHttpClient Method

clientConfig.register(AndroidFriendlyFeature.class);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated ApiClient.java buildHttpClient method and the Jersey 2 client configuration. Review the proposed AndroidFriendlyFeature and its HK2 filters, then check the Java client templates that produce this code. Done means the generated Android client suppresses the unsupported java.awt-related warnings without disrupting regular Java clients.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
api, mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.