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 8330485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:08:13+00:00 2026-06-09T02:08:13+00:00

I have a Grails service that sends out e-mails using a 3rd-party service by

  • 0

I have a Grails service that sends out e-mails using a 3rd-party service by doing a HTTP call:

class EmailService {
    def sendEmail(values) {
        def valueJson = values as JSON
        ... // does HTTP call to 3rd party service
    }
}

I’ve written a unit test to test this service (because an integration test spins up Hibernate and the entire domain framework, which I don’t need):

@TestFor(EmailService)
class EmailServiceTests {
    void testEmailServiceWorks() {
        def values = [test: 'test', test2: 'test2']
        service.sendEmail(values)
    }
}

However, when I execute this unit test, it fails with this exception when it tries to do the as JSON conversion:

org.apache.commons.lang.UnhandledException: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Unconvertable Object of class: java.util.LinkedHashMap

I then re-wrote my unit test to just do the following:

void testEmailServiceWorks() {
    def value = [test: 'test', test2: 'test2']
    def valueJson = value as JSON
}

And I get the same exception when it tries to do the as JSON conversion.

Does anyone know why I’m getting this exception, and how I can fix it?

  • 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-09T02:08:14+00:00Added an answer on June 9, 2026 at 2:08 am

    The as JSON magic is created when the domain framework spins up.

    You have to either change your test to an integration one or mock the asType.

    def setUp(){
        java.util.LinkedHashMap.metaClass.asType = { Class c ->
            new grails.converters."$c"(delegate)
        }
    }
    

    Rember to clean up after yourself in the tearDown, you wouldn’t want metaprogramming leaks in your test suite.

    def tearDown(){
        java.util.LinkedHashMap.metaClass.asType = null
    }
    

    Edit:
    If you come from the future, consider this answer: https://stackoverflow.com/a/15485593/194932

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

Sidebar

Related Questions

Using Grails and CXF, I have published a small web service that looks like
I have created one service in my grails application. in that service 25 methods
I have one grails application.In that I have one model class named Book. From
I have a Grails command object that contains an emailAddresses field, e.g. public class
We have an MTOM-enabled web service that is published with Grails and the Metro
I am using groovy/grails, and I have a ResultList in my service which I
I am working with grails. I have created a service that will delete the
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I'm using Grails and want to use groovyws to call an web-service. But my
We are using Grails [Spring+Hibernate] and have one service method with @Transactional(readOnly=true). During development

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.