question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not fully consistent ordering in spring-configuration-metadata.json

See original GitHub issue

Current comparator implementation produces not consistent order for special case, when a codebase contains multiple classes that shares same “namespace” and (optionally) same properties.

Consider this example:

package com.example;

@ConfigurationProperties("app.section")
public class Foo {
  private int val;
}

@ConfigurationProperties("app.section")
public class Bar {
  private boolean flag;
  private int val;
}

As both classes share same section (and it works in runtime just fine), this leads to multiple outcomes in groups sections, as well as in properties section:

  "groups": [
    {
      "name": "app.section",                          // order can be swapped!
      "type": "com.example.Foo",
      "sourceType": "com.example.Foo"
    },
    {
      "name": "app.section",
      "type": "com.example.Bar",
      "sourceType": "com.example.Bar""
    }
  ],

Same is applied for val in this exampe, as name is same, but type/sourceType is different.

I understand that this is extreme example, but it is valid in terms of spring support, so I think that adding sort stage for type can solve this problem:

private final Comparator<ItemMetadata> propertyComparator = Comparator.<ItemMetadata, Boolean>comparing(ItemMetadata::isDeprecated)
                .thenComparing(ItemMetadata::getName)
                .thenComparing(ItemMetadata::getType);
private final Comparator<ItemMetadata> groupComparator = Comparator.<ItemMetadata, String>comparing(ItemMetadata::getName).thenComparing(ItemMetadata::getType);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
zeldigascommented, Apr 23, 2021

Deal. I’m going to work on PR this weekend.

0reactions
zeldigascommented, Apr 25, 2021

OK, looks like I need to get familiar with the process better, sorry.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration Metadata - Spring
Configuration metadata files are located inside jars under META-INF/spring-configuration-metadata.json . They use a JSON format with items ...
Read more >
Accessing Spring Configuration Properties Metadata through ...
I would like to be able to add items to the metadata JSON and then retrieve them with the Spring API, instead of...
Read more >
A Guide to Spring Boot Configuration Metadata - Baeldung
In this tutorial, we'll explore the Spring Boot Configuration Processor and the associated JSON metadata files that document each property's ...
Read more >
Zalando RESTful API and Event Guidelines
The requirement level keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" used in this ...
Read more >
A Guide to Spring Boot Configuration Metadata - Morioh
In this tutorial, we'll explore the Spring Boot Configuration Processor and the associated JSON metadata files that document each property's meaning, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found