Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3940896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:28:31+00:00 2026-05-20T00:28:31+00:00

I am implementing a JAX-RS service in Scala using Jersey. I would to have

  • 0

I am implementing a JAX-RS service in Scala using Jersey. I would to have a generic trait for Json provider, and I need to know if the requested Class is supported by my provider. In java is not possible to know the class of a type parameter at runtime because the type erasure. But it is possible to do in scala?

This code does not work:

trait JsonProvider[A] extends MessageBodyReader[A] with MessageBodyWriter[A] {

  final def isReadable(t : Class[_],
             genericType: Type,
             annotations: Array[Annotation],
             mediaType: MediaType): Boolean = {
    t.isAssignableFrom(classOf[A]) && mediaType == MediaType.APPLICATION_JSON_TYPE
  }
}

Any suggestion? In Java the best method is to have a protected abstract method returning the class of A, in Scala too?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:28:32+00:00Added an answer on May 20, 2026 at 12:28 am

    There is workaround for this. You can use Manifest type class. By using it, Scala compiler will make sure, that class information would be available at runtime. Manifest has erasure property – it’s the class object for generic type.

    You can use it for method’s type parameters like this:

    def printClass[T](implicit ev: Manifest[T]) =
      println(ev.erasure.getSimpleName)
    

    or simlified:

    def printClass1[T: Manifest] =
      println(manifest[T].erasure.getSimpleName)
    

    You can also use it for classes or abstract classes:

    class Printer[T: Manifest] {
      def printName = println(manifest[T].erasure.getSimpleName)
    }
    

    Unfortunately you can’t use it for traits.

    Edit: As workaround, you can define trait like this:

    trait Printer[T] {
      def printName(implicit ev: Manifest[T]) =
        println(ev.erasure.getSimpleName)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a web service using JAX-WS and in the web.xml i had
confusion in using either jax-ws(java) or .NET for implementing the web services. i would
For a project I'm implementing a SOAP service using Apache Axis2 1.6.2. I have
I am implementing a Restful Web Service in java (JAX-RS) using Jesey. I run
I am in process of implementing a REST API server using Apache CXF JAX-RS
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I'm just getting acquainted with implementing REST web services in Java using JAX-RS and
implementing service something similar with tinyurl or bit.ly, I'm would like to expose service
When implementing a Matrix construct using arrays, which would be more efficient? Using a
I was doing some reading up on building a soap service using jax-ws as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.