7

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.

yahya
  • 4,810
  • 3
  • 41
  • 58

4 Answers4

11

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.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
3

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.

steve
  • 3,276
  • 27
  • 25
2

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.

Community
  • 1
  • 1
Bill Lin
  • 36
  • 1
  • I would recommend against using 1.x versions. But try 2.1.4 instead -- it is 2.x compatible. – StaxMan Apr 26 '13 at 17:07
  • Where can you find the download for the 2.1.x releases? I only see 2.2, and 1.x stuff listed on their site. – Jason Whitehorn May 03 '13 at 03:27
  • How do you get to _2.2_ without noticing that your 2 libraries can't be used together? NERD RAGE!! – steve May 04 '13 at 00:00
  • @JasonWhitehorn They are all in Maven central repo, so either change Maven deps, or modify link – StaxMan May 23 '13 at 21:04
  • 2
    [2.2.1](http://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core/2.2.1) also fixes this. – Joe May 29 '13 at 20:30
2

As steve says in his last edit, you can download the newest jars from Maven: http://repo1.maven.org/maven2/com/fasterxml/jackson/core/

Paris
  • 367
  • 3
  • 13