Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JacksonParser databind and core cause "Found duplicate file for APK"?

I'm trying to learn how to use jackson parser, to get more effective parsing on json data. I have these jar files: Downloaded from this page

 jackson-core-2.2.0.jar
 jackson-annotations-2.2.0.jar
 jackson-databind-2.2.0.jar

And in code, i just try to parse a json into an objects array:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String json = ReadFromRaw(this, R.raw.json);
    ArrayList<Category> categories = null;
    try {
        ObjectMapper mapper = new ObjectMapper(); 
        categories = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Category.class));
        // categories = mapper.readValue(json, new TypeReference<List<Category>>() {});
    } catch (Exception e) {
        Log.e("MainActivity", "Error: " + e.getMessage());
    }

    SimpleListView myList = (SimpleListView) findViewById(R.id.myList);
    myList.setAdapterWithItems(GetAdapter(categories));
} 

Not sure if necessary, but here is my Category class as well:

@JsonIgnoreProperties({ "DisplayPriority" })
public class Category {

    @JsonProperty("Id")
    private String categoryId;

    @JsonProperty("name")
    private String categoryName;

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

}

Everything seems ok, there is no error or warnings. But when i try to compile, it gives this error:

[2013-04-25 09:32:08 - Training - JacksonParser] Error generating final archive: Found duplicate file for APK: LICENSE
Origin 1: C:\~\workspace\Training - JacksonParser\libs\jackson-core-2.2.0.jar
Origin 2: C:\~\workspace\Training - JacksonParser\libs\jackson-databind-2.2.0.jar

As i search for this error on google, it says there is some class in common on these jar files. And i do not have any idea about what to do so... Is there something that i do wrong? Or i do something missing?

Thanks in advance, any help is appreciated.

like image 291
yahya Avatar asked Apr 25 '13 06:04

yahya


3 Answers

This problem has been reported for 2.2.0 release, see this issue; but should be resolved in 2.2.1.

EDIT: turns out that the main problem is that these files need to be located under META-INF/ in jar; if so, there is no conflict. And this is what 2.2.1 will do, once it is released.

like image 72
StaxMan Avatar answered Oct 04 '22 03:10

StaxMan


Kind of a pain, but it's not that bad to rebuild the jars manually.

git clone git://github.com/FasterXML/jackson-core.git
git clone git://github.com/FasterXML/jackson-databind.git
cd jackson-core
git checkout jackson-core-2.2.0b # not sure what the "b" is about
mv src/main/resources/NOTICE src/main/resources/META-INF/
mv src/main/resources/LICENSE src/main/resources/META-INF/
mvn install
# jar will be at target/jackson-core-2.2.0.jar

cd ../jackson-databind
git checkout jackson-databind-2.2.0
mv src/main/resources/NOTICE src/main/resources/META-INF/
mv src/main/resources/LICENSE src/main/resources/META-INF/
mvn install
# jar will be at target/jackson-databind-2.2.0.jar

Le sigh. What a pain.

EDIT: Turns out you need annotations to do most stuff. That exercise is left for the reader. I also found that you can download the jars for the new (fixed) version on Maven.

like image 28
steve Avatar answered Oct 04 '22 02:10

steve


I have the same problem. So, I use the old version.

jackson-core-asl-1.9.12.jar

jackson-mapper-asl-1.9.12.jar

You can download from "Latest stable 1.x version" of the same page.

like image 22
Bill Lin Avatar answered Oct 04 '22 02:10

Bill Lin