Skip to content

Conversation

@rbygrave
Copy link
Contributor

@rbygrave rbygrave commented Jan 8, 2025

Helps mostly when extracting values out of nested documents, and dealing with the various number types and type conversion

Example:

  String json = "{\"name\":\"Rob\",\"score\":4.5,\"whenActive\":\"2025-10-20\",\"address\":{\"street\":\"Pall Mall\"}}";
  Map<String, Object> mapFromJson = simpleMapper.fromJsonObject(json);

  JsonExtract extract = simpleMapper.extract(mapFromJson);

  String name = extract.extract("name");
  double score = extract.extract("score", -1D);
  String street = extract.extract("address.street");

  LocalDate activeDate = extract.extractOrEmpty("whenActive")
    .map(LocalDate::parse)
    .orElseThrow();

…er types from raw Map<String,Object>

Helps mostly when extracting values out of nested documents, and dealing with the various number types and type conversion
@rbygrave rbygrave requested a review from SentryMan January 8, 2025 08:46
@rbygrave rbygrave self-assigned this Jan 8, 2025
@rbygrave rbygrave merged commit 287d442 into main Jan 8, 2025
9 checks passed
@rbygrave rbygrave deleted the feature/core-JsonExtract branch January 8, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants