Skip to content

Docs: Adds section to README covering custom object parsing#500

Merged
bdemers merged 3 commits intoREADME-0-11-0from
docs-custom-parser
Oct 1, 2019
Merged

Docs: Adds section to README covering custom object parsing#500
bdemers merged 3 commits intoREADME-0-11-0from
docs-custom-parser

Conversation

@bdemers
Copy link
Member

@bdemers bdemers commented Sep 24, 2019

Doc: #495

@bdemers bdemers self-assigned this Sep 24, 2019
@bdemers bdemers added this to the 0.11.0 milestone Sep 24, 2019
@bdemers bdemers changed the title Adds section to README covering custom object parsing Docs: Adds section to README covering custom object parsing Sep 24, 2019
@coveralls
Copy link

coveralls commented Sep 24, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 725d2b6 on docs-custom-parser into 50fc773 on README-0-11-0.

.parseClaimsJwt(aJwtString)
.build()
.getBody()

Copy link
Contributor

Choose a reason for hiding this comment

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

Blank?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to follow what I thought was the existing convention, i.e.:

Jwts.parser()

    .setSigningKeyResolver(signingKeyResolver) // <----
    
    .parseClaimsJws(jwsString);

My personal pref is would be to strip those empty lines

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see what we did - it was to make it more visually obvious as to what is calling attention. Let's stick to the current convention, and we can have another PR if we want to change that convention.

Now that I'm looking at it, the extra lines with the // <----- makes it more visually obvious and probably enhances readability. Just my .02 though.

README.md Outdated
By default JJWT will only convert simple claim types: String, Date, Long, Integer, Short and Byte. If you need to deserialize other types you can configure the `JacksonDeserializer` by passing a `Map` of claim names to types in through a constructor. For example:

```java
new JacksonDeserializer(Maps.of("user", User.class))
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we show the constructor with ObjectMapper as an argument?

Copy link
Member Author

@bdemers bdemers Sep 25, 2019

Choose a reason for hiding this comment

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

This constructor will create and manipulate a new ObjectMapper (conventionally mapping the claims to types). This could cause unforeseen issues with an existing object mapper.

Anything more advanced then this, the JacksonDeserializer(ObjectMapper) constructor should be used instead (as shown in the previous section).

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is shouldn't there be a JacksonDeserializer(ObjectMapper, Map) constructor?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I think if you want to use a custom ObjectMapper, you would be in charge of configuring that instance. This constructor modifies the ObjectMapper, which could invalidate, or worse only slightly change how the ObjectMapper was originally configured.

You could end up in a situation where the same ObjectMapper is used for a few requests, then a JwtParser is constructed for the first time (with JacksonDeserializer(ObjectMapper, Map)) and this could change how future requests were parsed with the ObjectMapper in that application. For example, I couldn't use JacksonSerializer.DEFAULT_OBJECT_MAPPER for the same reason, as it would have changed how other JacksonDeserializers would parse.

That said this issue is specific to the readme, lets me move this over to #495 (I'll come back and tweak the doc with the signatures that we agree with)
https://github.com/jwtk/jjwt/pull/495/files#diff-43ca7dcadb15963ec66e63df02544e1aR68

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok, this is super helpful.

I think we need to be super clear about this in the documentation. For example, the very first sentence in the first section on Jackson states:

If you have an application-wide Jackson ObjectMapper (as is typically recommended for most applications), you can eliminate the overhead of JJWT constructing its own ObjectMapper by using yours instead.

I'm sure people would be curious why they can use their own ObjectMapper in one scenario, but not another, so this should be crystal clear in the docs IMO (i.e. in this PR).


```java
Jwts.parserBuilder()

Copy link
Contributor

Choose a reason for hiding this comment

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

Why the blank line? I don't think we do this in other parts of the doc, do we? Whatever we do, we should keep it consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was just trying to follow what I thought was the existing format, i.e.:

Jwts.parser()
    
    .setAllowedClockSkewSeconds(seconds) // <----
    
    // ... etc ...
    .parseClaimsJws(jwt);

My personal pref would be to strip the empty lines. My assumption was probably wrong, maybe the convention is to insert a new line between each line of code? (and keep any relevant comments directly above a given line)

Jwts.parserBuilder()

.deserializeJsonWith(new JacksonDeserializer(Maps.of("user", User.class)))

Copy link
Contributor

Choose a reason for hiding this comment

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

Blank?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, based on current convention, let's add a // <----- comment at the end of line 1340

README.md Outdated
By default JJWT will only convert simple claim types: String, Date, Long, Integer, Short and Byte. If you need to deserialize other types you can configure the `JacksonDeserializer` by passing a `Map` of claim names to types in through a constructor. For example:

```java
new JacksonDeserializer(Maps.of("user", User.class))
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok, this is super helpful.

I think we need to be super clear about this in the documentation. For example, the very first sentence in the first section on Jackson states:

If you have an application-wide Jackson ObjectMapper (as is typically recommended for most applications), you can eliminate the overhead of JJWT constructing its own ObjectMapper by using yours instead.

I'm sure people would be curious why they can use their own ObjectMapper in one scenario, but not another, so this should be crystal clear in the docs IMO (i.e. in this PR).

@bdemers
Copy link
Member Author

bdemers commented Oct 1, 2019

GitHub - Travis sync error, the build above is green, it shows up yellow/pending here.
merging...

@bdemers bdemers merged commit 9401953 into README-0-11-0 Oct 1, 2019
@bdemers bdemers deleted the docs-custom-parser branch October 1, 2019 18:35
lhazlewood pushed a commit that referenced this pull request Feb 4, 2020
- Docs: Adds section to README covering custom object parsing (#500)
- Docs: Add note about JwtParserBuilder creating an immutable JwtParser (#508)
Doc: #486
Fixes: #494
Doc: #495
Fixes: #171
lhazlewood pushed a commit that referenced this pull request Feb 5, 2020
- Docs: Adds section to README covering custom object parsing (#500)
- Docs: Add note about JwtParserBuilder creating an immutable JwtParser (#508)
Doc: #486
Fixes: #494
Doc: #495
Fixes: #171

Updated documentation and changelog to reflect the new Gson extension. Fixes #410. (#476)
lhazlewood added a commit that referenced this pull request Feb 5, 2020
…#559)

- Docs: Adds section to README covering custom object parsing (#500)
- Docs: Add note about JwtParserBuilder creating an immutable JwtParser (#508)
Doc: #486
Fixes: #494
Doc: #495
Fixes: #171

Updated documentation and changelog to reflect the new Gson extension. Fixes #410. (#476)

Co-authored-by: Brian Demers <brian.demers@gmail.com>
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