Skip to content
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

Add JavaDoc to 'Json' classes #12559

Closed
wants to merge 3 commits into from

Conversation

sbabcoc
Copy link
Contributor

@sbabcoc sbabcoc commented Aug 15, 2023

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

In this PR, I'm adding JavaDoc headers to the classes and methods of Selenium's Json API.

Motivation and Context

The Selenium Json API is a very useful built-in mechanism for consuming and producing JSON representations of Java objects. This facility can be very useful, especially when interacting with GraphQL web service endpoints, but the lack of documentation can result in considerable confusion.
This PR adds JavaDoc headers to classes, methods, and defined constants to assist folks in using the Selenium Json API in their own code.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sbabcoc sbabcoc marked this pull request as draft August 15, 2023 23:41
* <li>Classes that declare a {@code toJson()} method that returns primitives and collections.</li>
* </ul>
* </li>
* <li>Build-in deserialization of primitives and collections.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Built-in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

* <li>Build-in deserialization of primitives and collections.</li>
* <li>Facilities to deserialize custom data types:
* <ul>
* <li>Classes that declare setter methods that adhere to the {@code JavaBean} specification.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth pointing out that using the javabean spec makes instances mutable. The only way to get immutable instances is to use the fromJson method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note to this effect.

* <li>Facilities to deserialize custom data types:
* <ul>
* <li>Classes that declare setter methods that adhere to the {@code JavaBean} specification.</li>
* <li>Classes that declare a {@code fromJson(JsonInput)} method.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also use a fromJson(primitive) method if needed, which makes it easier to have "tiny types"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this, and I also noted the potential for producing immutable objects. I wasn't sure about how to document "tiny types", though.

* </li>
* </ul>
*
* The <b>Json</b> API also handles Selenium {@link org.openqa.selenium.Capabilities Capabilities} objects:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to point this out. The Capabilities interface as an asMap method, and that's used for serialising to json. There's no magic :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this bit.

* provide a {@code toJson()} method for the <b>Json</b> API to use for serialization. This is especially beneficial
* for objects that contain transient properties that should be omitted from the JSON output.
* <p>
* You can deserialize objects for which no explicit coercer has been defined via the <b>ObjectCoercer</b>. Note
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entry points for users of the JSON package are all in the Json class, though people might need to interact with a JsonInput. We shouldn't be encouraging people to look at the coercers.

The right thing to do is to use Json.toType(), which because of its funky signature will attempt to return the right type of object. You can use a TypeToken to coerce to novel types. eg Set<String> strings = Json.toType(input, new TypeToken<Set<String>>(){}.getType())

Copy link
Contributor Author

@sbabcoc sbabcoc Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revised this sentence to eliminate the overt reference to ObjectCoercer. I still need to introduce the concept of TypeToken specifications.

public class Json {
/** This constant declares the value of the {@code Content-Type}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc will know this is a constant anyway. You can just say "The value of the {@code Content-Type} headers of...."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

public static final String JSON_UTF_8 = "application/json; charset=utf-8";

/** This constant specifies deserializing as {@code List<Map<String, Object>} */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies here and elsewhere: we don't need to tell people a constant is a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

import java.lang.reflect.Type;

/**
* This enumeration is used to specify the strategy used to assign values during deserialization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to tell people this is an enum, so you can start the comment with "Used to specify...."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@sbabcoc sbabcoc force-pushed the pr/add-json-api-javadoc branch 3 times, most recently from 4a3fe16 to 10487f5 Compare August 17, 2023 07:58
@diemol
Copy link
Member

diemol commented Aug 23, 2023

Was this a duplicated PR?

@diemol
Copy link
Member

diemol commented Aug 23, 2023

I believe this is a duplicate of #12584

@diemol diemol closed this Aug 23, 2023
@sbabcoc sbabcoc deleted the pr/add-json-api-javadoc branch September 9, 2023 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants