Programming foundations

Stage 6 · Lesson 3 of 8

Files and JSON with Jackson

Build and ship your first projects

Java has no parser in its , so most projects add or Gson. With Jackson, an ObjectMapper turns JSON text into your own classes or , and back again. Turning objects into text and back like this is called serialisation.

mapper.readValue(file, Entry[].class) reads, and mapper.writerWithDefaultPrettyPrinter().writeValue(file, entries) writes. Records make good data classes for this. Missing and unknown fields are the common failure.

A missing field quietly becomes null or zero. How unknown fields are treated depends on the library and its settings. So validate after loading instead of trusting the file.

For , use Path and Files from java.nio.file and handle IOException. Keep loading and saving in one class, so the core logic works on plain objects.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • GitHub repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?