Add tests for json-customize example - #535
Conversation
Jackson, Flexjson으로 사용자 지정 JSON Writer를 사용한 부분은 7.2.1로 버전 업그레이드를 할 때, 기본으로 제공되는 StrutsJSONWriter 만 사용할 수 있어서, 아직은 7.1.1로 버전을 고정해두었다. 이 문제 현상에 대해서는 struts-example의 json-customize 예제에 테스트 코드를 추가해서 보고했다. * apache/struts-examples#535
|
@fp024 you must rebase onto main branch |
|
@lukaszlenart |
|
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. |
|
Test |
|
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 <bean type="org.apache.struts2.json.JSONWriter" name="flexJSONWriter" class="org.demo.FlexJSONWriter"
scope="prototype"/>
<constant name="struts.json.writer" value="flexJSONWriter"/> |
|
Thanks for that, I will double check what's wrong |
|
Nice, this is regression in Struts 7.2.1, I will prepare a fix. |
|
Ticket ready, on it |
|
Thank you very much for checking. Have a nice day! 👍 |
|
Thanks for this — the Heads up that #544 just landed and overlaps part of this PR, which is why it now shows conflicts. On current
So when you rebase, the XML parts of this PR can simply be dropped. Two of them would otherwise move things backwards:
The valuable parts — One thing to check while you're rebasing: CI is also currently red here ( |
|
Hi, thanks for the review! I've rebased the branch on Regarding Thanks! |
|
Update: Added a follow-up commit as the assertion update to json-unit-assert was missing after the rebase. |
|
Hello. The struts-6.5.dtd file has not been uploaded to https://struts.apache.org/dtds/. In the case of IntelliJ, there were no issues as it automatically reads the struts-6.5.dtd embedded in struts2-core-7.3.0.jar... However, in the VS Code + Red Hat XML Extension environment, a 404 error occurs because it attempts to download the DTD directly from the web at that address and cache it. https://struts.apache.org/dtds/struts-6.0.dtd is currently available for download. It seems that the struts-6.5.dtd file also needs to be uploaded. Please check into this. |
|
Good catch, I will fix that later, thanks! |
Summary
Adds JUnit tests for the
json-customizeexample.Motivation
This PR adds a reproducible JUnit test case to the
struts-examplesrepository 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-customizeexample 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, andorg.apache.struts2.json.StrutsJSONWriteris 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-examplesas a reproducible test case.Notes
The tests use "json-unit-assertj" to validate the serialized JSON output. The
lastLoginfield is validated by date format instead of comparing against a fixed value.Thanks 👍