-
Notifications
You must be signed in to change notification settings - Fork 619
fix: honor serialize false in JSONCompiled writers #7661
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
Changes from all commits
0cc63ee
0a2d3b7
92e9e28
81ad5e6
68cedd3
2b5b826
4dac8fd
4e9ef3f
050a2a7
a756388
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -127,19 +127,27 @@ private void findRelatedReferences() { | |||||||||
| continue; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| FieldInfo fieldInfo = new FieldInfo(); | ||||||||||
| FieldInfo readerFieldInfo = new FieldInfo(); | ||||||||||
| FieldInfo writerFieldInfo = new FieldInfo(); | ||||||||||
|
|
||||||||||
| String name = field.getSimpleName().toString(); | ||||||||||
| JSONField[] annotations = field.getAnnotationsByType(JSONField.class); | ||||||||||
| for (JSONField annotation : annotations) { | ||||||||||
| CodeGenUtils.getFieldInfo(fieldInfo, annotation, false); | ||||||||||
| CodeGenUtils.getFieldInfo(readerFieldInfo, annotation, false); | ||||||||||
| CodeGenUtils.getFieldInfo(writerFieldInfo, annotation, true); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] The new call Verified empirically:
Suggested change
Fix should be in if (!serialize && fieldInfo.ignore && feature == JSONReader.Feature.FieldBased) {
fieldInfo.ignore = false;
}— glm-5.2 via Qwen Code /review |
||||||||||
| } | ||||||||||
|
|
||||||||||
| if (fieldInfo.fieldName != null) { | ||||||||||
| name = fieldInfo.fieldName; | ||||||||||
| if (readerFieldInfo.fieldName != null) { | ||||||||||
| name = readerFieldInfo.fieldName; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| info.getAttributeByField(name, field); | ||||||||||
| AttributeInfo attr = info.getAttributeByField(name, field); | ||||||||||
| if (readerFieldInfo.ignore) { | ||||||||||
| attr.reader = false; | ||||||||||
| } | ||||||||||
| if (writerFieldInfo.ignore) { | ||||||||||
| attr.writer = false; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for (ExecutableElement method : ElementFilter.methodsIn(inheritance.getEnclosedElements())) { | ||||||||||
|
|
@@ -185,7 +193,25 @@ private void findRelatedReferences() { | |||||||||
| } else { | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| FieldInfo readerFieldInfo = new FieldInfo(); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Duplicated annotation-processing logic The reader/writer — glm-5.2 via Qwen Code /review |
||||||||||
| FieldInfo writerFieldInfo = new FieldInfo(); | ||||||||||
| JSONField[] annotations = method.getAnnotationsByType(JSONField.class); | ||||||||||
| for (JSONField annotation : annotations) { | ||||||||||
| CodeGenUtils.getFieldInfo(readerFieldInfo, annotation, false); | ||||||||||
| CodeGenUtils.getFieldInfo(writerFieldInfo, annotation, true); | ||||||||||
| } | ||||||||||
| if (readerFieldInfo.fieldName != null) { | ||||||||||
| name = readerFieldInfo.fieldName; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| AttributeInfo attr = info.getAttributeByMethod(name, type, getter, setter); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Dead code: the
Suggested change
— qwen3.7-max via Qwen Code /review |
||||||||||
| if (readerFieldInfo.ignore) { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] Split-attribute bypass: When a field has The same vulnerability exists for Consider propagating the field-level disable to the method-resolved attribute when the names diverge, or unifying disable tracking by Java property name rather than JSON name. — qwen3.7-max via Qwen Code /review |
||||||||||
| attr.reader = false; | ||||||||||
| } | ||||||||||
| if (writerFieldInfo.ignore) { | ||||||||||
| attr.writer = false; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ public class AttributeInfo | |
| ExecutableElement setMethod; | ||
| VariableElement argument; | ||
| long readerFeatures; | ||
| boolean reader = true; | ||
| boolean writer = true; | ||
|
|
||
| public AttributeInfo( | ||
| String name, | ||
|
|
@@ -35,7 +37,11 @@ public AttributeInfo( | |
| } | ||
|
|
||
| public boolean supportSet() { | ||
| return field != null || setMethod != null; | ||
| return reader && (field != null || setMethod != null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] Record canonical constructor arity mismatch with For records, Example: Fix: for records, the constructor call sites need ALL components regardless of the — qwen3.7-max via Qwen Code /review |
||
| } | ||
|
|
||
| public boolean supportGet() { | ||
| return writer && (field != null || getMethod != null); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Follow-up: the method-processing loop (lines 149-189) also never reads
@JSONFieldfrom getter/setter methods. If a user places@JSONField(serialize = false)on a getter (common JavaBeans pattern for private fields), the generated writer will still serialize the field — the same class of bug, on a different annotation target.Consider adding
method.getAnnotationsByType(JSONField.class)processing in the method loop to mirror the field-level fix:— qwen3.7-max via Qwen Code /review