nkuprins commented on issue #988:
URL: https://github.com/apache/fesod/issues/988#issuecomment-5253772388

   Thank you @MS-Jing, for #1006.  I checked your use case against the 
`@DictFormat` design to see whether one feature covers both, and it does. 
However, the initial focus of `@DictFormat` was only on scalar types. 
Concretely:
   
   ## Difference
   
   Both start from "the field stores `1`, the sheet should show `Normal`". They 
differ in what the Java field holds:
   
   | | #988 | #1006 |
   | --- | --- | --- |
   | Field declaration | `private Integer status;` | `private UserStatus 
status;` |
   | After a read, the field holds | `1` | `UserStatus.NORMAL` |
   | Enum's role | supplies the mapping, if you have one | **is** the value |
   
   ## They fit in one annotation
   
   ```java
   // 1. scalar field, mapping used once
   @DictFormat({"1=Success", "0=Failure"})
   private Integer status;
   
   // 2. scalar field, mapping already exists as an enum
   @DictFormat(mapping = Status.class)          // Status implements Dict: 
code() + label()
   private Integer status;
   
   // 3. the field IS the enum
   @DictFormat
   private UserStatus status;                // UserStatus implements Labeled: 
label()
   
   // 4. the field IS the enum, no annotation at all
   private UserStatus status;
   ```
   with two interfaces instead of one:
   
   ```java
   public interface Labeled { String label(); }
   public interface Dict extends Labeled { String code(); }
   ```
   
   _The reason for 2 interfaces is that in `2.` the enum has to say which 
scalar each constant stands for - that is `code()`. But in `3-4.` the field 
stores the constant itself. There is no separate stored value for `code()` to 
describe, so only the label is needed._
   \
   _Note: I changed `@DictFormat(type = Status.class) ` to `@DictFormat(mapping 
= Status.class) `, because otherwise it is confusing._
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to