JSON Encoder through Reflection API.
- 03-03-2025
- 10-03-2025
Use this project as the template for your implementation of a JSON Encoder.
You are only allowed to use AI tools, such as Copilot, ChatGPT, or others, for
requirement 2.2.
The rest of this assignment must be completed independently, as it is the only
way to fully grasp the use and purpose of Reflection.
Remember: "Programming is understanding." — Kristen Nygaard.
Implement the extension function fieldsToJson
(in FieldsToJson.kt
), which
converts the declared fields of a given object to JSON. This function should use
the Java Reflection API to inspect fields and recursively process non-primitive
types.
Your implementation should pass both testAddressFieldsToJson()
and
testClassroomFieldsToJson()
tests.
Implement the extension function membersToJson
(in MembersToJson.kt
) using
the Kotlin Reflection API.
This function encodes properties and non-void parameterless functions.
The membersToJson
function must be recursive.
- Members can be annotated with
ToJsonPropName
to replace the member's name with the specified JSON property name. - Members can also be annotated with
ToJsonFormatter
, which specifies a class implementing a function(Any) -> String
. This function provides an alternative JSON representation of the member's value, processing it.
- Your implementation should pass both
testClassroomMembersToJson()
andtestPersonMembersToJson()
tests. These tests utilize the domain model according to the following design:
-
Implement unit tests for a domain model of your choice that includes at least two associations, with one having a multiple multiplicity relationship. You may use any AI tool, such as Copilot, ChatGPT, or others, to assist you in implementing these unit tests and the domain model.
You must include your chosen domain here: https://github.com/isel-leic-ave/jsonoy/wiki/Student-Domain-Selections