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

  • Home
  • SEARCH
  • 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 8482819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:54:50+00:00 2026-06-10T19:54:50+00:00

I wrote a small service with Scalatra that does two things: serve JSON data

  • 0

I wrote a small service with Scalatra that does two things:

  • serve JSON data
  • serve same data as an Excel sheet

JSON is done with spray-json, Excel – with apache POI

Basically, I wrote two methods in my ScalatraServlet implementation:

def serveJson[T: JsonWriter](data: T) = {
  contentType = "text/json"
  data.toJson.prettyPrint
}

def serveExcel[T: ExcelWriter](data: T) = {
  contentType = "application/excel"
  data.toExcel.getBytes
}

Here, toJson is implemented with spray-json, so I just provide a JsonWriter implicit conversion. So I decided to write a similar toExcel conversion.

// ExcelWriter.scala

package com.example.app.excel

import org.apache.poi.hssf.usermodel.HSSFWorkbook
import annotation.implicitNotFound

@implicitNotFound(msg = "Cannot find ExcelWriter type class for ${T}")
trait ExcelWriter[T] {
  def write(obj: T): HSSFWorkbook
}

object ExcelWriter {
  implicit def func2Writer[T](f: T => HSSFWorkbook): ExcelWriter[T] = new ExcelWriter[T] {
    def write(obj: T) = f(obj)
  }
}


// Imports.scala
package com.example.app.excel

import org.apache.poi.hssf.usermodel.HSSFWorkbook

object Imports {

  type ExcelWriter[T] = com.example.app.excel.ExcelWriter[T]
  implicit def pimpAny[T](any: T) = new AnyExcelPimp(any)
  private[excel] class AnyExcelPimp[T](any: T) {
    def toExcel(implicit writer: ExcelWriter[T]): HSSFWorkbook = writer.write(any)
  }

}

Now, the problem is:

If I import import cc.spray.json._, then import excel.Imports._, scalac throws error in serveJson (value toJson is not a member of type parameter T)

If I import import excel.Imports._, then import cc.spray.json._, scalac throws analogous error in serveExcel (value toExcel is not a member of type parameter T)

Surprisingly, if I use only one of the imports, everything compiles and works just fine (well, half of it, since I comment out the half, that uses removed import).

What is wrong with my implementation?

Link to spray-json source, which I used as a reference: https://github.com/spray/spray-json/tree/master/src/main/scala/cc/spray/json

Scala version – 2.9.2

  • 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-06-10T19:54:52+00:00Added an answer on June 10, 2026 at 7:54 pm

    The problem seems to be that I used the same name for implicit conversion as the one used in spray-json: pimpAny.

    // my implicit
    implicit def pimpAny[T: ExcelWriter](any: T) = new AnyExcelPimp(any)
    
    // spray-json implicit
    implicit def pimpAny[T](any: T) = new PimpedAny(any)
    

    So a simple rename solved the problem.

    Still, kinda strange to not see the root problem but its result at compile time. Guess I’m to sleepy…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote small service class and I want implement something like that : service
I wrote a small express.js based web app. I serve a manifest.webapp but express.js
I wrote two small applications (a client and a server) to test UDP communication
I wrote two small java programs: a TCP client which sends many lines of
I wrote a small app that turns out to be using a lot of
I wrote a small program, that creates files at an interval of 1 minute.
I'm trying to write a small Windows Service in .NET 3.5, that check every
I am developing a small application that is going to serve as viewer (sort
I've written a small windows service that I want to run daily on my
I just wrote a small python script that gets me all the groups on

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.