-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Adding YamlSerializer Interface #33
Conversation
@amihaiemil Please review the code and tell me if I misunderstood something about the issue and any other comments :D |
1 similar comment
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.
@SherifWaly I reviewed the PR and I have few comments :)
|
||
/** | ||
* A Yaml serializer. | ||
* @author sherif |
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.
@SherifWaly Here it should be your name and email address between parentheses (see how it's in other classes)
@@ -0,0 +1,39 @@ | |||
package com.amihaiemil.camel; |
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.
@SherifWaly Add here the copyright notice (take it from other files)
* @return Yaml node | ||
* @TODO #30 Implement the serialize method with Map input and unit-test it. | ||
*/ | ||
YamlNode serialize(final Map<Object, Object> map); |
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.
@SherifWaly The interface should have only one method: YamlNode serialize();
. There will be 3 implementors of this interface. One implementor class will encapsulate a Map, another will encapsulate a Collection and the 3rd will encapsulate an Object.
e.g.
YamlSerializer objectToYaml = YamlObjectSerializer(object);
YamlNode mapping1 = objectToYaml.serialize();
YamlSerializer mapToYaml = YamlMapSerializer(map);
YamlNode mapping2 = mapToYaml .serialize();
YamlSerializer collectionToYaml = YamlCollectionSerializer(collection);
YamlNode sequence= collectionToYaml .serialize();
Also, each implementor will override the return type of the method (you can do that, as long as the overriding type is a subtype
of the initial one). E.g. YamlCollectionSerializer
will have the method YamlSequence serialize();
- that is possible because YamlSequence
extends YamlNode
The way you wrote it is also a way of doing it, of course, but a class with these 3 methods would just be a bag of functions, I don't think it would encapsulate anything. An object should always encapsulate something - if it just has some utility methods, it is not a proper object, that's what I think.
* Serialize a Map<Object, Object> to YamlNode. | ||
* @param map Map<Object, Object> | ||
* @return Yaml node | ||
* @TODO #30 Implement the serialize method with Map input and unit-test it. |
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.
@SherifWaly The format of the puzzle is almost correct, but not entirely. The letters todo
need to be lowercase, and after #30
, you need to add the estimation and role: :30m/DEV
. Also, the text needs to be changed. One good puzzle would be:
@todo #30:30m/DEV This interface should have 3 implementor classes: YamlObjectSerializer,
YamlMapSerializer and YamlCollectionSerializer. Each of these classes will encapsulate and serialize
the mentioned types (i.e. Object, Map<Object, Object> and Collection<Object). The return type
or method ``serialize()`` should be overridden with the proper subtype (e.g. YamlObjectSerializer will
have the method ``YamlMapping serialize() {...}``
Notice that at the beginning of each new line, there is a space (it is important because otherwise, the bot won't parse it right). #30
is the parent ticket, while :30m/DEV
is the estimation and role.
Now, of course, the puzzle asks for a lot of effort, which will take more than 30min, for sure, but this puzzle will be broken in more puzzles. Whoever will take it, will implement just one part of it (one of the classes), and will leave other puzzles in the code to cover the rest of the task. Makes sense? :)
1 similar comment
@amihaiemil please check the new commit :) |
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.
@SherifWaly I got 2 comments. Let's discuss this a little, you gave me some ideas :D
* proper subtype (e.g. YamlObjectSerializer will have the method | ||
* ``YamlMapping serialize() {...}`` | ||
* | ||
* @todo #30:30m/TEST This interface should be tested by 3 unit tests: |
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.
@SherifWaly This puzzle is not needed. :) It should be understood from the puzzle above that unit tests are also expected. I mean, with any implementation, a unit test is always required, right? How else do we know the new code works and doesn't break anything?
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.
You are right for that but I thought it could be separated to make the puzzles smaller :D
* of YamlNode (e.g. YamlObjectSerializer in objectYamlSerialize() test should | ||
* return a proper YamlMapping) | ||
* | ||
* @todo #30:30m/DEV New interface which is YamlPresenter should be implemented |
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.
@SherifWaly This is interesting. How did you think about this interface. How would it be used? :D
The specification says there are 3 stages: Representation, Serialization and Presentation. It is this diagram
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.
@amihaiemil I opened the specification and found this diagram. I think the Serializer would create the Tree as each YamlNode has its children. So I think this interface would work on traversing this tree and creating a Presentation for this tree to be readable.
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.
@amihaiemil Also should I add a puzzle for reversing this process for the other 3 stages: Construct, Compose and Parse ?
@SherifWaly You got a good idea. There is only one misunderstanding (it's my fault). The word "Serialization" from this interface had nothing to do with the serialization tree from the specification. By "serializing" an object, map or collection, I simply meant "turn it into a YamlNode" (which, in fact, is the representation, the first step from the diagram). Let's forget about this PR and clearly think about the "dumping" process (representing -> serialializing -> presenting). I think this would be a good way of doing it (turn a Student into a Yaml) Student john = new Student ("John", "Doe", "Computer Science");
YamlMapping yaml = new Yaml(john).represent();
YamlMapping serialized = yaml.serialize();
String printed = serialized.present(); or, a shorter, more fluent version Student john = new Student ("John", "Doe", "Computer Science");
String printed = new Yaml(john).represent().serialize().present(); What do you think? I think it's great because the user can choose to have the yaml serialized or not.
Don't write any code, we're just discussing now ^^ |
I think this a good idea as we will have several options for presenting the output. So know we should exchange YamlSerializer with YamlRepresenter which should do the same task and 2 extra interfaces will be as puzzles which are YamlSerializer (or another name as it will handle 2 options) and the YamlPresenter interface. I think you've meant that, right? :D |
Rename it Student john = new Student ("John", "Doe", "Computer Science");
YamlDump yaml = new YamlObjectDump(john);
String printed = yaml.represent().serialize().present(); ^ this will print the yaml serialized (with the duplicates replaced by aliases) Student john = new Student ("John", "Doe", "Computer Science");
YamlDump yaml = new YamlObjectDump(john);
String printed = yaml.represent().present(); I don't think we need the other 2 interfaces. Anyway, the direction sounds good. Let's do the representation and worry about serialization and presentation later. |
Ok, I will rename it to |
@amihaiemil please check last commit and see if we could open issues for serializing and presenting stage. |
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.
Just 1 comment
* @since 1.0.0 | ||
* | ||
* @todo #30:30m/DEV This interface should have 3 implementor classes: | ||
* YamlObjectDump, YamlMapDump and YamlCollectionDump. |
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.
@SherifWaly add a space at the beginning of each new line, otherwise the puzzels won't be well processed by the bot :)
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.
@amihaiemil please check if it's fixed :)
@SherifWaly looks ok:) |
@rultor merge |
@amihaiemil OK, I'll try to merge now. You can check the progress of the merge here |
@amihaiemil Done! FYI, the full log is here (took me 1min) |
This PR is for #30