Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add recommended configuration for Jackson JsonPropertyOrder #1048

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion idea-plugin/src/main/resources/.recommend.easy.api.config
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,46 @@ field.mock[@com.fasterxml.jackson.annotation.JsonFormat]=groovy:```
return "@datetime(\"" + it.ann("com.fasterxml.jackson.annotation.JsonFormat","pattern") + "\")"
```

#[Jackson_JsonPropertyOrder]
#Support for Jackson annotation JsonPropertyOrder
[email protected]#index
json.class.parse.before[@com.fasterxml.jackson.annotation.JsonPropertyOrder]=groovy:```
def properties = it.annValue("com.fasterxml.jackson.annotation.JsonPropertyOrder")
properties.each { property ->
session.push("JsonPropertyOrder-properties-"+it.name(), property)
}
session.set("JsonPropertyOrder-alphabetic"+it.name(),
it.annValue("com.fasterxml.jackson.annotation.JsonPropertyOrder","alphabetic") ?: false)
```
json.class.parse.after[@com.fasterxml.jackson.annotation.JsonPropertyOrder]=groovy:```
session.remove("JsonPropertyOrder-properties-"+it.name())
session.remove("JsonPropertyOrder-"+it.name())
```
field.order=groovy:```
def index = session.get("JsonPropertyOrder-properties-"+ it.containingClass().name())?.indexOf(it.name())
if (index == -1) {
return null
}else{
return index
}
```
field.order.with=groovy:```
def orderedProperties = session.get("JsonPropertyOrder-properties-"+ a.containingClass().name())
if(a.name() in orderedProperties) {
if(b.name() in orderedProperties){
return orderedProperties.indexOf(a.name()) - orderedProperties.indexOf(b.name())
}else{
return -1
}
} else if(b.name() in orderedProperties){
return 1
} else if(session.get("JsonPropertyOrder-alphabetic"+a.containingClass().name())){
return a.name().compareTo(b.name())
} else {
return null
}
```

#[Jackson_JsonIgnoreProperties]
#Support for Jackson annotation JsonIgnoreProperties

Expand Down Expand Up @@ -689,10 +729,22 @@ field.order.with=groovy:```
def aDefineClass = a.defineClass()
def bDefineClass = b.defineClass()
if(aDefineClass==bDefineClass){
return 0
return null
}else if(aDefineClass.isExtend(bDefineClass.name())){
return 1
}else{
return -1
}
```

#[field_order_alphabetically]
# fields alphabetically ordered
field.order.with=groovy:```
return a.name().compareTo(b.name())
```

#[field_order_alphabetically_descending]
# fields descending alphabetically ordered
field.order.with=groovy:```
return -a.name().compareTo(b.name())
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.itangcent.idea.plugin.settings.helper

import com.itangcent.mock.toUnixString
import com.itangcent.test.ResultLoader
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -79,9 +80,60 @@ internal class RecommendConfigLoaderTest {

@Test
fun testCodes() {
assertEquals(
"[module, ignore, deprecated_java, deprecated_kotlin, not_ignore_irregular_api_method, Jackson, Jackson_JsonIgnoreProperties, Jackson_JsonUnwrapped, Gson, ignore_transient_field, converts, spring_Entity, spring_webflux, spring.validations, spring.ui, jakarta.validation, jakarta.validation(strict), javax.validation, javax.validation(strict), is_file, yapi_tag, yapi_tag_kotlin, yapi_status, yapi_mock, yapi_tag, import_spring_properties, resolve_spring_properties, ignore_serialVersionUID, support_mock_for_general, private_protected_field_only, support_mock_for_javax_validation, not_ignore_static_final_field, Jackson_JsonNaming, Jackson_UpperCamelCaseStrategy, Jackson_SnakeCaseStrategy, Jackson_LowerCaseStrategy, Jackson_KebabCaseStrategy, Jackson_LowerDotCaseStrategy, properties, Fastjson, enum_auto_select_field_by_type, enum_use_name, enum_use_ordinal, ignore_some_common_classes, field_order, field_order_child_first, field_order_parent_first]",
RecommendConfigLoader.codes().contentToString()
assertArrayEquals(
arrayOf(
"module",
"ignore",
"deprecated_java",
"deprecated_kotlin",
"not_ignore_irregular_api_method",
"Jackson",
"Jackson_JsonPropertyOrder",
"Jackson_JsonIgnoreProperties",
"Jackson_JsonUnwrapped",
"Gson",
"ignore_transient_field",
"converts",
"spring_Entity",
"spring_webflux",
"spring.validations",
"spring.ui",
"jakarta.validation",
"jakarta.validation(strict)",
"javax.validation",
"javax.validation(strict)",
"is_file",
"yapi_tag",
"yapi_tag_kotlin",
"yapi_status",
"yapi_mock",
"yapi_tag",
"import_spring_properties",
"resolve_spring_properties",
"ignore_serialVersionUID",
"support_mock_for_general",
"private_protected_field_only",
"support_mock_for_javax_validation",
"not_ignore_static_final_field",
"Jackson_JsonNaming",
"Jackson_UpperCamelCaseStrategy",
"Jackson_SnakeCaseStrategy",
"Jackson_LowerCaseStrategy",
"Jackson_KebabCaseStrategy",
"Jackson_LowerDotCaseStrategy",
"properties",
"Fastjson",
"enum_auto_select_field_by_type",
"enum_use_name",
"enum_use_ordinal",
"ignore_some_common_classes",
"field_order",
"field_order_child_first",
"field_order_parent_first",
"field_order_alphabetically",
"field_order_alphabetically_descending"
),
RecommendConfigLoader.codes()
)

}
Expand Down
Loading