Skip to content

Add tests for json-customize example#535

Open
fp024 wants to merge 3 commits into
apache:mainfrom
fp024:DEV-2026-07-06
Open

Add tests for json-customize example#535
fp024 wants to merge 3 commits into
apache:mainfrom
fp024:DEV-2026-07-06

Conversation

@fp024

@fp024 fp024 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds JUnit tests for the json-customize example.

Motivation

This PR adds a reproducible JUnit test case to the struts-examples repository to make it easier to verify the behavior of the custom JSON writer configuration.

With Struts 7.1.1, the custom JSON writer configured by the json-customize example is used as expected. However, after changing only the Struts version to 7.2.1, the configured custom JSON writer no longer appears to be selected, and org.apache.struts2.json.StrutsJSONWriter is used instead.

The behavior can be reproduced or verified by changing only the Struts version to 7.2.1 and running the added tests.

Since the Struts main repository does not have the Issues tab enabled, I am submitting this to struts-examples as a reproducible test case.

Notes

The tests use "json-unit-assertj" to validate the serialized JSON output. The lastLogin field is validated by date format instead of comparing against a fixed value.

Thanks 👍

fp024 added a commit to fp024/struts2-study that referenced this pull request Jul 6, 2026
Jackson, Flexjson으로 사용자 지정 JSON Writer를 사용한 부분은 7.2.1로 버전 업그레이드를 할 때,
기본으로 제공되는 StrutsJSONWriter 만 사용할 수 있어서, 아직은 7.1.1로 버전을 고정해두었다.

이 문제 현상에 대해서는 struts-example의 json-customize 예제에 테스트 코드를 추가해서 보고했다.
* apache/struts-examples#535
Comment thread json-customize/pom.xml Outdated
@lukaszlenart

Copy link
Copy Markdown
Member

@fp024 you must rebase onto main branch

@fp024
fp024 force-pushed the DEV-2026-07-06 branch from 74d3dac to b7b7b9f Compare July 6, 2026 13:23
@fp024

fp024 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@lukaszlenart
Rebased onto the latest main branch. Thank you.

- fix flexjson serialization to fully exclude null fields

- replace JSON verification with "json-unit-assertj"
@fp024

fp024 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

When flexjson excludes fields with null values, it leaves trailing keys behind, which results in an invalid JSON string. I have pushed an additional commit to resolve this issue.

@lukaszlenart

Copy link
Copy Markdown
Member

Test ProduceActionTest fails

@fp024

fp024 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I added and shared this test case specifically because it fails on Struts 7.2.1 while passing completely on Struts 7.1.1.

On Struts 7.2.1, the following configuration does not take effect, and the system is seemingly forced to use only the default StrutsJSONWriter instead of our custom bean:

  <bean type="org.apache.struts2.json.JSONWriter" name="flexJSONWriter" class="org.demo.FlexJSONWriter"
        scope="prototype"/>
  <constant name="struts.json.writer" value="flexJSONWriter"/>

@lukaszlenart

Copy link
Copy Markdown
Member

Thanks for that, I will double check what's wrong

@lukaszlenart

Copy link
Copy Markdown
Member

Nice, this is regression in Struts 7.2.1, I will prepare a fix.

@lukaszlenart

Copy link
Copy Markdown
Member

Ticket ready, on it
https://issues.apache.org/jira/browse/WW-5641

@fp024

fp024 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Thank you very much for checking. Have a nice day! 👍

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