Correct set of dependencies for using Jackson mapper

后端 未结 5 922
半阙折子戏
半阙折子戏 2020-12-05 09:28

I am new to Jackson and I was writing some code for practice. I found out the the new version of Jackson library can be found on Fasterxml: Jackson, so I added the below dep

相关标签:
5条回答
  • 2020-12-05 09:44

    Apart from fixing the imports, do a fresh maven clean compile -U. Note the -U option, that brings in new dependencies which sometimes the editor has hard time with. Let the compilation fail due to un-imported classes, but at least you have an option to import them after the maven command.

    Just doing Maven->Reimport from Intellij did not work for me.

    0 讨论(0)
  • 2020-12-05 09:48

    The package names in Jackson 2.x got changed to com.fasterxml1 from org.codehaus2. So if you just need ObjectMapper, I think Jackson 1.X can satisfy with your needs.

    0 讨论(0)
  • 2020-12-05 09:48

    I spent few hours on this.

    Even if I had the right dependency the problem was fixed only after I deleted the com.fasterxml.jackson folder in the .m2 repository under C:\Users\username.m2 and updated the project

    0 讨论(0)
  • 2020-12-05 09:59

    No, you can simply use com.fasterxml.jackson.databind.ObjectMapper. Most likely you forgot to fix your import-statements, delete all references to codehaus and you're golden.

    0 讨论(0)
  • <properties>
      <!-- Use the latest version whenever possible. -->
      <jackson.version>2.4.4</jackson.version>
    </properties>
    <dependencies>
       <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
      </dependency>
    </dependencies>
    

    you have a ObjectMapper (from Jackson Databind package) handy. if so, you can do:

    JsonFactory factory = objectMapper.getFactory();
    

    Source: https://github.com/FasterXML/jackson-core

    So, the 3 "fasterxml" dependencies which you already have in u'r pom are enough for ObjectMapper as it includes jackson-databind.

    0 讨论(0)
提交回复
热议问题