Git Product home page Git Product logo

Comments (5)

bdemers avatar bdemers commented on June 19, 2024

I need clarification on what you are asking.
https://stackoverflow.com/help/how-to-ask

What line throws an exception?

from jpaseto.

anand-mm avatar anand-mm commented on June 19, 2024

java.lang.ClassCastException: java.lang.String cannot be cast to dev.paseto.jpaseto.Paseto

I tried using instanceof keyword in java it did not work:

    public Integer pasetoclaims(Object clientToken, String param) {
        Integer result = null;
        Paseto token = null;
        try {
            if(clientToken instanceof Paseto)
                token = (Paseto) clientToken;
            if (param.contains("name"))
                result = token.getClaims().get("name", Integer.class);
            else
                result = token.getClaims().get(param, Integer.class);
        } catch (Exception e) {
           e.printStackTrace();
        }
        return result;
    }

I also tried using getclass but it did not work,

    public Integer pasetoclaims(Object clientToken, String param) {
        Integer result = null;
        Paseto token = null;
        try {
            if(clientToken.getClass().equals(Paseto.class))     //This is where i have used getclass
                token = (Paseto) clientToken;
            if (param.contains("name"))
                result = token.getClaims().get("name", Integer.class);
            else
                result = token.getClaims().get(param, Integer.class);
        } catch (Exception e) {
           e.printStackTrace();
        }
        return result;
    }

Can anyone suggest how to cast it in a proper way . Thanks in advance.

In this method i have getting paseto token in clientToken as a String datatype and i am casting the clientToken to Paseto for getting the Paseto Token claims. when checking in if condition with instanceof that is skipped.without if condition classcastexception in 6 line

token = (Paseto) clientToken

from jpaseto.

bdemers avatar bdemers commented on June 19, 2024

Sorry @anand-mm, I think I'm missing something.
Are you trying to cast a String to a Paseto object directly?
If so please look at: https://github.com/paseto-toolkit/jpaseto#paseto-read

Otherwise, can you create an example project on GitHub that demos the problem and link it here?

from jpaseto.

anand-mm avatar anand-mm commented on June 19, 2024

Yes I am trying to cast String to Paseto Object directly. It is Possible or not??

from jpaseto.

bdemers avatar bdemers commented on June 19, 2024

No, that is not possible Java.

Take a look at this section of the docs to learn how to parse a [String] PASETO token: https://github.com/paseto-toolkit/jpaseto#paseto-read

from jpaseto.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.